package com.example.elm.Home_Page;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import androidx.viewpager.widget.ViewPager;

import com.example.elm.R;
import com.example.elm.SQL.Connection_SQL;
import com.example.elm.ViewPagerAdapter;

import org.checkerframework.checker.units.qual.C;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Check_Shop_Data_Page extends AppCompatActivity {

    ViewPager view_page;
    TextView choose_food_page_text_view, choose_discount_food_page_text_view, comment_page_text_view, how_many_comment, check_merchant_page_text_view;
    View choose_food_page_view, choose_discount_food_page_view, comment_page_view, check_merchant_page_view;
    TextView last_text_view, last_specification_text_view, note_text, choose_how_many_table_ware;
    LinearLayout last_specification_view;
    CardView last_view;
    View last_view_in_view_page;
    RelativeLayout set_check_out_dialog;
    TextView how_many_product, should_pay_how_much, reduce_how_many_money, delivery_fee;
    Button go_to_check_page;
    LinearLayout set_which_coupon;
    LinearLayout last_choose_which_table_ware;
    LinearLayout last_choose_how_many_table_ware;
    TextView user_name_text_view, user_sex_text_view, user_phone_number_text_view;

    List<View> viewList_in_view_page = new ArrayList<>();
    ArrayList<String> category = new ArrayList<>();
    int which_list = 0;
    boolean is_loading_product_data = false, is_loading_category_data = false, is_loading_coupon_data = false;
    String email = "", user_location = "", shop_name = "", user_email = "";
    HashMap<String, Integer> choose_which_category = new HashMap<>();
    HashMap<String, Discount_Data> set_discount_data = new HashMap<>();
    List<View_List> viewList = new ArrayList<>();
    AlertDialog dialog, loading_page_dialog;
    int buy_how_many_product = 0;
    HashMap<String, Integer> choose_how_many_product = new HashMap<>();
    double how_many_dollars = 0, reduce_how_many_dollars = 0;
    boolean is_show_check_out_bottom = false;
    int loading_which_index = 0;
    HashMap<String, List<Product_Data>> product_data = new HashMap<>();
    List<View> get_view_y = new ArrayList<>();
    List<CardView> item_card_view = new ArrayList<>();
    HashMap<String, Integer> coupon_data = new HashMap<>();
    HashMap<Boolean, Integer> how_many_single_order_without_delivery = new HashMap<>();
    int delivery_time = 0;
    double packing_fee = 0, reduce_after_delivery_fee = 0, reduce_how_many_delivery_fee = 0;
    HashMap<String, Integer> product_main_name = new HashMap<>();
    HashMap<String, Product_Specification_Or_Attributes_Data> product_second_data = new HashMap<>();
    Check_Coupon_Thread checkCouponThread;
    int table_ware_num = 1;
    String user_name = "", user_phone_number = "", user_sex = "";
    double how_long = 0;
    String user_sex_temp = "先生";
    int how_many_product_category = 0, all_has_how_many_product = 0;

    private class Product_Data_Thread extends Thread {

        LinearLayout set_category_layout, product_list_layout;
        ScrollView set_category_list_view, product_list_view;
        String category_name;
        CardView item;

        public Product_Data_Thread(LinearLayout set_category_layout, LinearLayout product_list_layout, ScrollView set_category_list_view, ScrollView product_list_view, String category_name, CardView item) {
            this.set_category_layout = set_category_layout;
            this.product_list_layout = product_list_layout;
            this.set_category_list_view = set_category_list_view;
            this.product_list_view = product_list_view;
            this.category_name = category_name;
            this.item = item;
        }

        @Override
        public void run() {
            is_loading_product_data = false;

            ExecutorService executorService = Executors.newSingleThreadExecutor();
            executorService.execute(() -> {
                try {
                    Connection_SQL userSQL = new Connection_SQL();
                    Connection connection = userSQL.connection();
                    List<Product_Data> temp = new ArrayList<>();
                    String sql2 = "SELECT * FROM `" + email + "_merchant_product` where category_1 = ? or category_2 = ? or category_3 = ? or category_4 = ? or category_5 = ?;";
                    PreparedStatement preparedStatement = connection.prepareStatement(sql2);
                    System.out.println(category_name);
                    preparedStatement.setString(1, category_name);
                    preparedStatement.setString(2, category_name);
                    preparedStatement.setString(3, category_name);
                    preparedStatement.setString(4, category_name);
                    preparedStatement.setString(5, category_name);
                    ResultSet set2 = preparedStatement.executeQuery();
                    while (set2.next()) {
                        Product_Data productData = new Product_Data();
                        productData.product_name = set2.getString("name");
                        productData.product_pic = set2.getBytes("picture");
                        productData.product_price = String.valueOf(set2.getDouble("product_price"));
                        productData.sold = String.valueOf(set2.getInt("sold"));
                        productData.is_single_order_without_delivery = String.valueOf(set2.getInt("is_single_order_without_delivery"));
                        productData.specification_name = set2.getString("specification_name");
                        productData.specification_data = set2.getString("specification_data");
                        productData.attributes_name = set2.getString("attributes_name");
                        productData.attributes_label = set2.getString("attributes_label");
                        productData.min_purchase = String.valueOf(set2.getInt("min_purchase"));
                        choose_how_many_product.put(set2.getString("name"), 0);
                        product_main_name.put(set2.getString("name"), 0);

                        temp.add(productData);
                    }
                    product_data.put(category_name, temp);

                    String sql3 = "SELECT * FROM merchant_discount_product_page WHERE email = ?;";
                    preparedStatement = connection.prepareStatement(sql3);
                    preparedStatement.setString(1, email);
                    ResultSet set3 = preparedStatement.executeQuery();
                    while (set3.next()) {
                        String discount_product_name = set3.getString("all_product_name");
                        String discount_product_data = set3.getString("all_product_data");
                        String discount_product_name_temp = "";
                        int discount_product_data_loop = 0;

                        for (int i = 0; i < discount_product_name.length(); i++) {
                            if (discount_product_name.charAt(i) == ',') {
                                Discount_Data discountData = new Discount_Data();
                                String discount_product_data_temp = "";
                                int loop_which = 0;
                                for (int j = discount_product_data_loop; j < discount_product_data.length(); j++) {
                                    if (discount_product_data.charAt(j) == ',') {
                                        if (discount_product_data_temp.equals("所有折扣数据已添加")) {
                                            set_discount_data.put(discount_product_name_temp, discountData);
                                            discount_product_name_temp = "";
                                            discount_product_data_loop = j + 1;
                                            break;
                                        } else {
                                            if (loop_which == 0) {
                                                discountData.discount_price = Double.parseDouble(discount_product_data_temp);
                                            } else if (loop_which == 1) {
                                                discountData.is_purchase_limit_in_order = Integer.parseInt(discount_product_data_temp);
                                            } else if (loop_which == 2) {
                                                discountData.is_purchase_limit_in_inventory = Integer.parseInt(discount_product_data_temp);
                                            } else if (loop_which == 3) {
                                                discountData.set_order_purchase_limit = Integer.parseInt(discount_product_data_temp);
                                            } else if (loop_which == 4) {
                                                discountData.set_inventory_purchase_limit = Integer.parseInt(discount_product_data_temp);
                                            }
                                            loop_which += 1;
                                            discount_product_data_temp = "";
                                        }
                                    } else {
                                        discount_product_data_temp += discount_product_data.charAt(j);
                                    }
                                }
                            } else {
                                discount_product_name_temp += discount_product_name.charAt(i);
                            }
                        }
                    }
                    is_loading_product_data = true;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });

            while (!is_loading_product_data) {
                try {
                    Thread.sleep(1);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    View_List view_list = new View_List();
                    choose_which_category.put(category_name, 0);
                    View view2 = LayoutInflater.from(Check_Shop_Data_Page.this).inflate(R.layout.set_category_layout_to_add_discount_page_product_view, null);
                    get_view_y.add(view2);
                    TextView category_in_product_name = view2.findViewById(R.id.category_in_product_name);
                    category_in_product_name.setText(category_name);
                    LinearLayout product = view2.findViewById(R.id.product);
                    if (product_data.containsKey(category_name)) {
                        for (int j = 0; j < product_data.get(category_name).size(); j++) {
                            View view3 = LayoutInflater.from(Check_Shop_Data_Page.this).inflate(R.layout.set_choose_discount_page_product_card_view, null);

                            ImageView product_pic_image = view3.findViewById(R.id.product_pic);
                            Bitmap decodedImage = BitmapFactory.decodeByteArray(product_data.get(category_name).get(j).product_pic, 0, product_data.get(category_name).get(j).product_pic.length);
                            product_pic_image.setImageBitmap(decodedImage);

                            TextView product_name = view3.findViewById(R.id.product_name);
                            product_name.setText(product_data.get(category_name).get(j).product_name);

                            TextView original_price = view3.findViewById(R.id.original_price);

                            TextView discount = view3.findViewById(R.id.discount);
                            LinearLayout discount_layout = view3.findViewById(R.id.discount_layout);

                            TextView product_price = view3.findViewById(R.id.product_price);
                            if (set_discount_data.containsKey(product_data.get(category_name).get(j).product_name)) {
                                product_price.setText("" + set_discount_data.get(product_data.get(category_name).get(j).product_name).discount_price);
                                original_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                                original_price.setText("¥" + product_data.get(category_name).get(j).product_price);

                                double how_many_discount = set_discount_data.get(product_data.get(category_name).get(j).product_name).discount_price / Double.parseDouble(product_data.get(category_name).get(j).product_price) * 10;

                                discount.setText(String.format("%.2f", how_many_discount) + "折");
                            } else {
                                product_price.setText(product_data.get(category_name).get(j).product_price);
                                original_price.setVisibility(View.GONE);
                                discount_layout.setVisibility(View.GONE);
                            }

                            TextView this_product_sold_in_month = view3.findViewById(R.id.this_product_sold_in_month);
                            this_product_sold_in_month.setText("月售" + product_data.get(category_name).get(j).sold);

                            LinearLayout is_single_order_without_delivery = view3.findViewById(R.id.is_single_order_without_delivery);
                            if (product_data.get(category_name).get(j).is_single_order_without_delivery.equals("1")) {
                                is_single_order_without_delivery.setVisibility(View.VISIBLE);
                            } else {
                                is_single_order_without_delivery.setVisibility(View.GONE);
                            }

                            LinearLayout choose_specification_or_attributes = view3.findViewById(R.id.choose_specification_or_attributes);
                            TextView is_specification_or_attributes = view3.findViewById(R.id.is_specification_or_attributes);
                            TextView how_many_in_this_product_in_has_specification_or_attributes = view3.findViewById(R.id.how_many_in_this_product_in_has_specification_or_attributes);

                            TextView how_many_in_this_product = view3.findViewById(R.id.how_many_in_this_product);
                            LinearLayout delete_specification_or_attributes = view3.findViewById(R.id.delete_specification_or_attributes);

                            if (!product_data.get(category_name).get(j).specification_name.isEmpty() || !product_data.get(category_name).get(j).attributes_name.isEmpty()) {
                                is_specification_or_attributes.setText("选规格");
                                int finalJ = j;
                                choose_specification_or_attributes.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        set_dialog();
                                        List<String> specification_name = new ArrayList<>();
                                        List<List<String>> specification_data = new ArrayList<>();
                                        List<String> attributes_name = new ArrayList<>();
                                        List<List<String>> attributes_data = new ArrayList<>();
                                        String specification_temp = "";
                                        String attributes_temp = "";

                                        for (int k = 0; k < product_data.get(category_name).get(finalJ).specification_name.length(); k++) {
                                            if (product_data.get(category_name).get(finalJ).specification_name.charAt(k) == ',') {
                                                specification_name.add(specification_temp);
                                                specification_temp = "";
                                            } else {
                                                specification_temp += product_data.get(category_name).get(finalJ).specification_name.charAt(k);
                                            }
                                        }

                                        specification_temp = "";
                                        List<String> specification_data_temp_list = new ArrayList<>();

                                        for (int k = 0; k < product_data.get(category_name).get(finalJ).specification_data.length(); k++) {
                                            if (product_data.get(category_name).get(finalJ).specification_data.charAt(k) == ',') {
                                                if (specification_temp.equals("规格数据已添加")) {
                                                    specification_data.add(specification_data_temp_list);
                                                    specification_data_temp_list = new ArrayList<>();
                                                } else {
                                                    specification_data_temp_list.add(specification_temp);
                                                }
                                                specification_temp = "";
                                            } else {
                                                specification_temp += product_data.get(category_name).get(finalJ).specification_data.charAt(k);
                                            }
                                        }

                                        for (int k = 0; k < product_data.get(category_name).get(finalJ).attributes_name.length(); k++) {
                                            if (product_data.get(category_name).get(finalJ).attributes_name.charAt(k) == ',') {
                                                attributes_name.add(attributes_temp);
                                                attributes_temp = "";
                                            } else {
                                                attributes_temp += product_data.get(category_name).get(finalJ).attributes_name.charAt(k);
                                            }
                                        }

                                        attributes_temp = "";
                                        List<String> attributes_data_temp_list = new ArrayList<>();

                                        for (int k = 0; k < product_data.get(category_name).get(finalJ).attributes_label.length(); k++) {
                                            if (product_data.get(category_name).get(finalJ).attributes_label.charAt(k) == ',') {
                                                if (attributes_temp.equals("属性添加完毕")) {
                                                    attributes_data.add(attributes_data_temp_list);
                                                    attributes_data_temp_list = new ArrayList<>();
                                                } else {
                                                    attributes_data_temp_list.add(attributes_temp);
                                                }
                                                attributes_temp = "";
                                            } else {
                                                attributes_temp += product_data.get(category_name).get(finalJ).attributes_label.charAt(k);
                                            }
                                        }

                                        dialog.dismiss();

                                        List<String> choose_which_specification_or_attributes_list = new ArrayList<>();
                                        List<TextView> choose_which_specification_or_attributes_text_view_list = new ArrayList<>();

                                        Dialog dialog = new Dialog(view.getContext());
                                        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                                        dialog.setContentView(R.layout.set_choose_specification_attributes_view);

                                        LinearLayout choose_specification_or_attributes = dialog.findViewById(R.id.choose_specification_or_attributes);
                                        LinearLayout delete_specification_or_attributes = dialog.findViewById(R.id.delete_specification_or_attributes);
                                        TextView how_many_in_this_product = dialog.findViewById(R.id.how_many_in_this_product);
                                        TextView discount = dialog.findViewById(R.id.discount);
                                        LinearLayout discount_layout = dialog.findViewById(R.id.discount_layout);
                                        TextView is_set_min_purchase = dialog.findViewById(R.id.is_set_min_purchase);
                                        TextView original_price = dialog.findViewById(R.id.original_price);
                                        original_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                                        TextView product_price = dialog.findViewById(R.id.product_price);
                                        TextView product_name = dialog.findViewById(R.id.product_name);
                                        product_name.setText(product_data.get(category_name).get(finalJ).product_name);
                                        LinearLayout set_attributes = dialog.findViewById(R.id.set_attributes);
                                        LinearLayout is_set_height = dialog.findViewById(R.id.is_set_height);
                                        LinearLayout add_specification = dialog.findViewById(R.id.add_specification);
                                        LinearLayout set_choose_which_specification_or_attributes = dialog.findViewById(R.id.set_choose_which_specification_or_attributes);
                                        LinearLayout rowLL = new LinearLayout(dialog.getContext());
                                        LinearLayout.LayoutParams rowLP =
                                                new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                                        ViewGroup.LayoutParams.WRAP_CONTENT);

                                        float rowMargin = dipToPx(10);
                                        rowLP.setMargins(0, (int) rowMargin, 0, 0);
                                        rowLL.setLayoutParams(rowLP);
                                        boolean isNewLayout = false;
                                        float maxWidth = getScreenWidth() - dipToPx(30);
                                        float elseWidth = maxWidth;
                                        LinearLayout.LayoutParams textViewLP =
                                                new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                                                        ViewGroup.LayoutParams.WRAP_CONTENT);
                                        textViewLP.setMargins((int) dipToPx(8), 0, 0, 0);

                                        List<TextView> last_attributes_text_view_list = new ArrayList<>();

                                        if (specification_name.isEmpty()) {
                                            is_set_height.setVisibility(View.GONE);
                                        }

                                        if (set_discount_data.containsKey(product_data.get(category_name).get(finalJ).product_name)) {
                                            product_price.setText("" + set_discount_data.get(product_data.get(category_name).get(finalJ).product_name).discount_price);
                                            original_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                                            original_price.setText("¥" + product_data.get(category_name).get(finalJ).product_price);

                                            double how_many_discount = set_discount_data.get(product_data.get(category_name).get(finalJ).product_name).discount_price / Double.parseDouble(product_data.get(category_name).get(finalJ).product_price) * 10;

                                            discount.setText(String.format("%.2f", how_many_discount) + "折");
                                        } else {
                                            product_price.setText(product_data.get(category_name).get(finalJ).product_price);
                                            original_price.setVisibility(View.GONE);
                                            discount_layout.setVisibility(View.GONE);
                                        }

                                        for (int k = 0; k < specification_name.size(); k++) {
                                            if (isNewLayout) {
                                                add_specification.addView(rowLL);
                                                rowLL = new LinearLayout(dialog.getContext());
                                                rowLL.setLayoutParams(rowLP);
                                                isNewLayout = false;
                                            }
                                            View view1 = getLayoutInflater().inflate(R.layout.set_specification_card, null);
                                            LinearLayout choose_this_specification = view1.findViewById(R.id.choose_this_specification);
                                            TextView specification_name_text_view = view1.findViewById(R.id.specification_name);
                                            TextView specification_price_text_view = view1.findViewById(R.id.specification_price);
                                            specification_name_text_view.setText(specification_name.get(k));
                                            specification_price_text_view.setText(specification_data.get(k).get(0));

                                            View choose_which_specification_or_attributes_view = LayoutInflater.from(dialog.getContext()).inflate(R.layout.set_choose_which_specification_or_attributes_text_view, null);
                                            TextView choose_which_specification_or_attributes_text_view = choose_which_specification_or_attributes_view.findViewById(R.id.choose_which_specification_or_attributes_text_view);

                                            if (k == 0) {
                                                last_specification_view = choose_this_specification;
                                                last_specification_text_view = specification_name_text_view;
                                                choose_this_specification.setBackgroundResource(R.drawable.border_white_2_10dp);
                                                specification_name_text_view.setTextColor(Color.rgb(224, 143, 87));
                                                choose_which_specification_or_attributes_text_view.setText(specification_name.get(k));
                                                set_choose_which_specification_or_attributes.addView(choose_which_specification_or_attributes_view);
                                                choose_which_specification_or_attributes_text_view_list.add(choose_which_specification_or_attributes_text_view);
                                                choose_which_specification_or_attributes_list.add(specification_name.get(k));

                                                if (product_data.get(category_name).get(finalJ).attributes_name.isEmpty()) {
                                                    if (Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase) > 1) {
                                                        if (!choose_how_many_product.containsKey(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，")) {
                                                            if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) == 0) {
                                                                is_set_min_purchase.setText("+" + product_data.get(category_name).get(finalJ).min_purchase + "份起购");
                                                            } else {
                                                                is_set_min_purchase.setText("+加入购物车");
                                                            }
                                                            how_many_in_this_product.setVisibility(View.GONE);
                                                            delete_specification_or_attributes.setVisibility(View.GONE);
                                                        } else {
                                                            if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) == 0) {
                                                                is_set_min_purchase.setText("+" + product_data.get(category_name).get(finalJ).min_purchase + "份起购");
                                                                how_many_in_this_product.setVisibility(View.GONE);
                                                                delete_specification_or_attributes.setVisibility(View.GONE);
                                                                choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，", 0);
                                                            } else {
                                                                is_set_min_purchase.setText("+");
                                                                how_many_in_this_product.setVisibility(View.VISIBLE);
                                                                delete_specification_or_attributes.setVisibility(View.VISIBLE);
                                                                how_many_in_this_product.setText("" + choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，"));
                                                            }
                                                        }
                                                    } else {
                                                        if (!choose_how_many_product.containsKey(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，") || choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，") == 0) {
                                                            is_set_min_purchase.setText("+加入购物车");
                                                            how_many_in_this_product.setVisibility(View.GONE);
                                                            delete_specification_or_attributes.setVisibility(View.GONE);
                                                        } else {
                                                            is_set_min_purchase.setText("+");
                                                            how_many_in_this_product.setVisibility(View.VISIBLE);
                                                            delete_specification_or_attributes.setVisibility(View.VISIBLE);
                                                            how_many_in_this_product.setText("" + choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，"));
                                                        }
                                                    }
                                                }
                                            }
                                            int finalK = k;
                                            choose_this_specification.setOnClickListener(new View.OnClickListener() {
                                                @Override
                                                public void onClick(View view) {
                                                    if (last_specification_view != choose_this_specification) {
                                                        choose_this_specification.setBackgroundResource(R.drawable.border_white_2_10dp);
                                                        specification_name_text_view.setTextColor(Color.rgb(224, 143, 87));
                                                        last_specification_view.setBackgroundResource(R.drawable.border_bar_color_10dp);
                                                        last_specification_text_view.setTextColor(Color.BLACK);
                                                        last_specification_view = choose_this_specification;
                                                        last_specification_text_view = specification_name_text_view;

                                                        choose_which_specification_or_attributes_text_view_list.get(0).setText(specification_name.get(finalK));
                                                        choose_which_specification_or_attributes_list.set(0, specification_name.get(finalK));

                                                        if (set_discount_data.containsKey(product_data.get(category_name).get(finalJ).product_name)) {
                                                            double how_many_price = Double.parseDouble(specification_data.get(finalK).get(0)) * (set_discount_data.get(product_data.get(category_name).get(finalJ).product_name).discount_price / Double.parseDouble(product_data.get(category_name).get(finalJ).product_price) * 10 * 10) / 100;
                                                            product_price.setText(String.format("%.1f", how_many_price));
                                                            original_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                                                            original_price.setText("¥" + specification_data.get(finalK).get(0));
                                                        } else {
                                                            product_price.setText(specification_data.get(finalK).get(0));
                                                            original_price.setVisibility(View.GONE);
                                                            discount_layout.setVisibility(View.GONE);
                                                        }

                                                        String attributes_temp = "";
                                                        for (int i = 0; i < last_attributes_text_view_list.size(); i++) {
                                                            attributes_temp += last_attributes_text_view_list.get(i).getText().toString();
                                                            attributes_temp += "，";
                                                        }
                                                        if (Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase) > 1) {
                                                            if (!choose_how_many_product.containsKey(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp)) {
                                                                if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) == 0) {
                                                                    is_set_min_purchase.setText("+" + product_data.get(category_name).get(finalJ).min_purchase + "份起购");
                                                                } else {
                                                                    is_set_min_purchase.setText("+加入购物车");
                                                                }
                                                                how_many_in_this_product.setVisibility(View.GONE);
                                                                delete_specification_or_attributes.setVisibility(View.GONE);
                                                            } else {
                                                                if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) == 0) {
                                                                    is_set_min_purchase.setText("+" + product_data.get(category_name).get(finalJ).min_purchase + "份起购");
                                                                    how_many_in_this_product.setVisibility(View.GONE);
                                                                    delete_specification_or_attributes.setVisibility(View.GONE);
                                                                    choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp, 0);
                                                                } else {
                                                                    is_set_min_purchase.setText("+");
                                                                    how_many_in_this_product.setVisibility(View.VISIBLE);
                                                                    delete_specification_or_attributes.setVisibility(View.VISIBLE);
                                                                    how_many_in_this_product.setText("" + choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp));
                                                                }
                                                            }
                                                        } else {
                                                            if (!choose_how_many_product.containsKey(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp) || choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp) == 0) {
                                                                is_set_min_purchase.setText("+加入购物车");
                                                                how_many_in_this_product.setVisibility(View.GONE);
                                                                delete_specification_or_attributes.setVisibility(View.GONE);
                                                            } else {
                                                                is_set_min_purchase.setText("+");
                                                                how_many_in_this_product.setVisibility(View.VISIBLE);
                                                                delete_specification_or_attributes.setVisibility(View.VISIBLE);
                                                                how_many_in_this_product.setText("" + choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp));
                                                            }
                                                        }
                                                    }
                                                }
                                            });
                                            view1.measure(0, 0);
                                            if (maxWidth < view1.getMeasuredWidth()) {
                                                add_specification.addView(rowLL);
                                                rowLL = new LinearLayout(dialog.getContext());
                                                rowLL.setLayoutParams(rowLP);
                                                rowLL.addView(view1);
                                                isNewLayout = true;
                                                continue;
                                            }
                                            if (elseWidth < view1.getMeasuredWidth()) {
                                                isNewLayout = true;
                                                k--;
                                                elseWidth = maxWidth;
                                                continue;
                                            } else {
                                                elseWidth -= view1.getMeasuredWidth() + dipToPx(8);
                                                if (rowLL.getChildCount() == 0) {
                                                    rowLL.addView(view1);
                                                } else {
                                                    view1.setLayoutParams(textViewLP);
                                                    rowLL.addView(view1);
                                                }
                                            }
                                        }

                                        add_specification.removeView(rowLL);
                                        add_specification.addView(rowLL);

                                        for (int k = 0; k < attributes_name.size(); k++) {
                                            View set_attributes_name_view = LayoutInflater.from(dialog.getContext()).inflate(R.layout.set_attributes_name, null);
                                            TextView set_attributes_name = set_attributes_name_view.findViewById(R.id.set_attributes_name);
                                            LinearLayout add_attributes_label = set_attributes_name_view.findViewById(R.id.add_attributes_label);
                                            set_attributes_name.setText(attributes_name.get(k));

                                            LinearLayout attributes_rowLL = new LinearLayout(dialog.getContext());
                                            LinearLayout.LayoutParams attributes_rowLP =
                                                    new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                                            ViewGroup.LayoutParams.WRAP_CONTENT);

                                            attributes_rowLP.setMargins(0, (int) rowMargin, 0, 0);
                                            attributes_rowLL.setLayoutParams(attributes_rowLP);
                                            isNewLayout = false;
                                            LinearLayout.LayoutParams attributes_textViewLP =
                                                    new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                                                            ViewGroup.LayoutParams.WRAP_CONTENT);
                                            attributes_textViewLP.setMargins((int) dipToPx(8), 0, 0, 0);

                                            for (int l = 0; l < attributes_data.get(k).size(); l++) {
                                                if (isNewLayout) {
                                                    add_attributes_label.addView(attributes_rowLL);
                                                    attributes_rowLL = new LinearLayout(dialog.getContext());
                                                    attributes_rowLL.setLayoutParams(rowLP);
                                                    isNewLayout = false;
                                                }
                                                TextView attributes_label_name = (TextView) getLayoutInflater().inflate(R.layout.set_attributes_label_view, null);
                                                attributes_label_name.setText(attributes_data.get(k).get(l));

                                                View choose_which_specification_or_attributes_view = getLayoutInflater().inflate(R.layout.set_choose_which_specification_or_attributes_text_view, null);
                                                TextView choose_which_specification_or_attributes_text_view = choose_which_specification_or_attributes_view.findViewById(R.id.choose_which_specification_or_attributes_text_view);

                                                if (l == 0) {
                                                    if ((specification_name.isEmpty() && k == choose_which_specification_or_attributes_list.size()) || (!specification_name.isEmpty() && k + 1 == choose_which_specification_or_attributes_list.size())) {
                                                        choose_which_specification_or_attributes_text_view_list.add(choose_which_specification_or_attributes_text_view);
                                                        choose_which_specification_or_attributes_list.add(attributes_data.get(k).get(l));
                                                        set_choose_which_specification_or_attributes.addView(choose_which_specification_or_attributes_view);
                                                        attributes_label_name.setBackgroundResource(R.drawable.border_white_2_10dp);
                                                        attributes_label_name.setTextColor(Color.rgb(224, 143, 87));
                                                        last_attributes_text_view_list.add(attributes_label_name);
                                                        attributes_temp = "";
                                                        for (int i = 0; i < last_attributes_text_view_list.size(); i++) {
                                                            attributes_temp += last_attributes_text_view_list.get(i).getText().toString();
                                                            attributes_temp += "，";
                                                        }
                                                        if (choose_which_specification_or_attributes_list.isEmpty()) {
                                                            choose_which_specification_or_attributes_text_view.setText(attributes_data.get(k).get(l));
                                                            if (Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase) > 1) {
                                                                if (!choose_how_many_product.containsKey(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp)) {
                                                                    if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) == 0) {
                                                                        is_set_min_purchase.setText("+" + product_data.get(category_name).get(finalJ).min_purchase + "份起购");
                                                                    } else {
                                                                        is_set_min_purchase.setText("+加入购物车");
                                                                    }
                                                                    how_many_in_this_product.setVisibility(View.GONE);
                                                                    delete_specification_or_attributes.setVisibility(View.GONE);
                                                                } else {
                                                                    if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) == 0) {
                                                                        is_set_min_purchase.setText("+" + product_data.get(category_name).get(finalJ).min_purchase + "份起购");
                                                                        how_many_in_this_product.setVisibility(View.GONE);
                                                                        delete_specification_or_attributes.setVisibility(View.GONE);
                                                                        choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp, 0);
                                                                    } else if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp) == 0) {
                                                                        is_set_min_purchase.setText("+加入购物车");
                                                                        how_many_in_this_product.setVisibility(View.GONE);
                                                                        delete_specification_or_attributes.setVisibility(View.GONE);
                                                                    } else {
                                                                        is_set_min_purchase.setText("+");
                                                                        how_many_in_this_product.setVisibility(View.VISIBLE);
                                                                        delete_specification_or_attributes.setVisibility(View.VISIBLE);
                                                                        how_many_in_this_product.setText("" + choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp));
                                                                    }
                                                                }
                                                            } else {
                                                                if (!choose_how_many_product.containsKey(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp) || choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp) == 0) {
                                                                    is_set_min_purchase.setText("+加入购物车");
                                                                    how_many_in_this_product.setVisibility(View.GONE);
                                                                    delete_specification_or_attributes.setVisibility(View.GONE);
                                                                } else {
                                                                    is_set_min_purchase.setText("+");
                                                                    how_many_in_this_product.setVisibility(View.VISIBLE);
                                                                    delete_specification_or_attributes.setVisibility(View.VISIBLE);
                                                                    how_many_in_this_product.setText("" + choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp));
                                                                }
                                                            }
                                                        } else {
                                                            choose_which_specification_or_attributes_text_view.setText("、" + attributes_data.get(k).get(l));
                                                            if (Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase) > 1) {
                                                                if (!choose_how_many_product.containsKey(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp)) {
                                                                    if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) == 0) {
                                                                        is_set_min_purchase.setText("+" + product_data.get(category_name).get(finalJ).min_purchase + "份起购");
                                                                    } else {
                                                                        is_set_min_purchase.setText("+加入购物车");
                                                                    }
                                                                    how_many_in_this_product.setVisibility(View.GONE);
                                                                    delete_specification_or_attributes.setVisibility(View.GONE);
                                                                } else {
                                                                    if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) == 0) {
                                                                        is_set_min_purchase.setText("+" + product_data.get(category_name).get(finalJ).min_purchase + "份起购");
                                                                        how_many_in_this_product.setVisibility(View.GONE);
                                                                        delete_specification_or_attributes.setVisibility(View.GONE);
                                                                        choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp, 0);
                                                                    } else if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp) == 0) {
                                                                        is_set_min_purchase.setText("+加入购物车");
                                                                        how_many_in_this_product.setVisibility(View.GONE);
                                                                        delete_specification_or_attributes.setVisibility(View.GONE);
                                                                    } else {
                                                                        is_set_min_purchase.setText("+");
                                                                        how_many_in_this_product.setVisibility(View.VISIBLE);
                                                                        delete_specification_or_attributes.setVisibility(View.VISIBLE);
                                                                        how_many_in_this_product.setText("" + choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp));
                                                                    }
                                                                }
                                                            } else {
                                                                if (!choose_how_many_product.containsKey(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp) || choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp) == 0) {
                                                                    is_set_min_purchase.setText("+加入购物车");
                                                                    how_many_in_this_product.setVisibility(View.GONE);
                                                                    delete_specification_or_attributes.setVisibility(View.GONE);
                                                                } else {
                                                                    is_set_min_purchase.setText("+");
                                                                    how_many_in_this_product.setVisibility(View.VISIBLE);
                                                                    delete_specification_or_attributes.setVisibility(View.VISIBLE);
                                                                    how_many_in_this_product.setText("" + choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp));
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                int finalK = k;
                                                int finalL = l;
                                                attributes_label_name.setOnClickListener(new View.OnClickListener() {
                                                    @Override
                                                    public void onClick(View view) {
                                                        if (last_attributes_text_view_list.get(finalK) != attributes_label_name) {
                                                            last_attributes_text_view_list.get(finalK).setBackgroundResource(R.drawable.border_bar_color_10dp);
                                                            last_attributes_text_view_list.get(finalK).setTextColor(Color.BLACK);
                                                            attributes_label_name.setBackgroundResource(R.drawable.border_white_2_10dp);
                                                            attributes_label_name.setTextColor(Color.rgb(224, 143, 87));
                                                            last_attributes_text_view_list.set(finalK, attributes_label_name);
                                                            if (specification_name.isEmpty()) {
                                                                choose_which_specification_or_attributes_text_view_list.get(finalK).setText(attributes_data.get(finalK).get(finalL));
                                                                choose_which_specification_or_attributes_list.set(finalK, attributes_data.get(finalK).get(finalL));
                                                            } else {
                                                                choose_which_specification_or_attributes_text_view_list.get(finalK + 1).setText("、" + attributes_data.get(finalK).get(finalL));
                                                                choose_which_specification_or_attributes_list.set(finalK + 1, attributes_data.get(finalK).get(finalL));
                                                            }

                                                            String attributes_temp = "";
                                                            for (int i = 0; i < last_attributes_text_view_list.size(); i++) {
                                                                attributes_temp += last_attributes_text_view_list.get(i).getText().toString();
                                                                attributes_temp += "，";
                                                            }

                                                            if (specification_name.isEmpty()) {
                                                                if (Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase) > 1) {
                                                                    if (!choose_how_many_product.containsKey(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp)) {
                                                                        if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) == 0) {
                                                                            is_set_min_purchase.setText("+" + product_data.get(category_name).get(finalJ).min_purchase + "份起购");
                                                                        } else {
                                                                            is_set_min_purchase.setText("+加入购物车");
                                                                        }
                                                                        how_many_in_this_product.setVisibility(View.GONE);
                                                                        delete_specification_or_attributes.setVisibility(View.GONE);
                                                                    } else {
                                                                        if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) == 0) {
                                                                            is_set_min_purchase.setText("+" + product_data.get(category_name).get(finalJ).min_purchase + "份起购");
                                                                            how_many_in_this_product.setVisibility(View.GONE);
                                                                            delete_specification_or_attributes.setVisibility(View.GONE);
                                                                            choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp, 0);
                                                                        } else if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp) == 0) {
                                                                            is_set_min_purchase.setText("+加入购物车");
                                                                            how_many_in_this_product.setVisibility(View.GONE);
                                                                            delete_specification_or_attributes.setVisibility(View.GONE);
                                                                        } else {
                                                                            is_set_min_purchase.setText("+");
                                                                            how_many_in_this_product.setVisibility(View.VISIBLE);
                                                                            delete_specification_or_attributes.setVisibility(View.VISIBLE);
                                                                            how_many_in_this_product.setText("" + choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp));
                                                                        }
                                                                    }
                                                                } else {
                                                                    if (!choose_how_many_product.containsKey(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp) || choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp) == 0) {
                                                                        is_set_min_purchase.setText("+加入购物车");
                                                                        how_many_in_this_product.setVisibility(View.GONE);
                                                                        delete_specification_or_attributes.setVisibility(View.GONE);
                                                                    } else {
                                                                        is_set_min_purchase.setText("+");
                                                                        how_many_in_this_product.setVisibility(View.VISIBLE);
                                                                        delete_specification_or_attributes.setVisibility(View.VISIBLE);
                                                                        how_many_in_this_product.setText("" + choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp));
                                                                    }
                                                                }
                                                            } else {
                                                                if (Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase) > 1) {
                                                                    if (!choose_how_many_product.containsKey(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp)) {
                                                                        if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) == 0) {
                                                                            is_set_min_purchase.setText("+" + product_data.get(category_name).get(finalJ).min_purchase + "份起购");
                                                                        } else {
                                                                            is_set_min_purchase.setText("+加入购物车");
                                                                        }
                                                                        how_many_in_this_product.setVisibility(View.GONE);
                                                                        delete_specification_or_attributes.setVisibility(View.GONE);
                                                                    } else {
                                                                        if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) == 0) {
                                                                            is_set_min_purchase.setText("+" + product_data.get(category_name).get(finalJ).min_purchase + "份起购");
                                                                            how_many_in_this_product.setVisibility(View.GONE);
                                                                            delete_specification_or_attributes.setVisibility(View.GONE);
                                                                            choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp, 0);
                                                                        } else if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp) == 0) {
                                                                            is_set_min_purchase.setText("+加入购物车");
                                                                            how_many_in_this_product.setVisibility(View.GONE);
                                                                            delete_specification_or_attributes.setVisibility(View.GONE);
                                                                        } else {
                                                                            is_set_min_purchase.setText("+");
                                                                            how_many_in_this_product.setVisibility(View.VISIBLE);
                                                                            delete_specification_or_attributes.setVisibility(View.VISIBLE);
                                                                            how_many_in_this_product.setText("" + choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp));
                                                                        }
                                                                    }
                                                                } else {
                                                                    if (!choose_how_many_product.containsKey(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp) || choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp) == 0) {
                                                                        is_set_min_purchase.setText("+加入购物车");
                                                                        how_many_in_this_product.setVisibility(View.GONE);
                                                                        delete_specification_or_attributes.setVisibility(View.GONE);
                                                                    } else {
                                                                        is_set_min_purchase.setText("+");
                                                                        how_many_in_this_product.setVisibility(View.VISIBLE);
                                                                        delete_specification_or_attributes.setVisibility(View.VISIBLE);
                                                                        how_many_in_this_product.setText("" + choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp));
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                });
                                                attributes_label_name.measure(0, 0);
                                                if (maxWidth < attributes_label_name.getMeasuredWidth()) {
                                                    add_attributes_label.addView(attributes_rowLL);
                                                    attributes_rowLL = new LinearLayout(dialog.getContext());
                                                    attributes_rowLL.setLayoutParams(attributes_rowLP);
                                                    attributes_rowLL.addView(attributes_label_name);
                                                    isNewLayout = true;
                                                    continue;
                                                }
                                                if (elseWidth < attributes_label_name.getMeasuredWidth()) {
                                                    isNewLayout = true;
                                                    l--;
                                                    elseWidth = maxWidth;
                                                    continue;
                                                } else {
                                                    elseWidth -= attributes_label_name.getMeasuredWidth() + dipToPx(8);
                                                    if (attributes_rowLL.getChildCount() == 0) {
                                                        attributes_rowLL.addView(attributes_label_name);
                                                    } else {
                                                        attributes_label_name.setLayoutParams(textViewLP);
                                                        attributes_rowLL.addView(attributes_label_name);
                                                    }
                                                }
                                            }

                                            add_attributes_label.removeView(attributes_rowLL);
                                            add_attributes_label.addView(attributes_rowLL);

                                            set_attributes.addView(set_attributes_name_view);
                                        }

                                        choose_specification_or_attributes.setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                if (!is_show_check_out_bottom) {
                                                    AnimationSet animationSet = (AnimationSet) AnimationUtils.loadAnimation(Check_Shop_Data_Page.this, R.anim.show_check_out_bottom);
                                                    set_check_out_dialog.startAnimation(animationSet);
                                                    set_check_out_dialog.setVisibility(View.VISIBLE);
                                                    is_show_check_out_bottom = true;
                                                }

                                                String attributes_temp = "";
                                                for (int i = 0; i < last_attributes_text_view_list.size(); i++) {
                                                    attributes_temp += last_attributes_text_view_list.get(i).getText().toString();
                                                    attributes_temp += "，";
                                                }

                                                if (specification_name.isEmpty()) {
                                                    if (!product_second_data.containsKey(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp)) {
                                                        Product_Specification_Or_Attributes_Data productSpecificationOrAttributesData = new Product_Specification_Or_Attributes_Data();
                                                        productSpecificationOrAttributesData.setMain_name(product_data.get(category_name).get(finalJ).product_name);
                                                        productSpecificationOrAttributesData.setSpecification_or_attributes(attributes_temp);
                                                        productSpecificationOrAttributesData.setHow_many(0);
                                                        productSpecificationOrAttributesData.setThis_product_has_how_many_discount_product(0);
                                                        if (set_discount_data.containsKey(product_data.get(category_name).get(finalJ).product_name)) {
                                                            productSpecificationOrAttributesData.setOne_this_product_original_price(Double.parseDouble(original_price.getText().toString().substring(1)));
                                                            productSpecificationOrAttributesData.setOne_this_product_discount(Double.parseDouble(product_price.getText().toString()));
                                                        }
                                                        else {
                                                            productSpecificationOrAttributesData.setOne_this_product_original_price(Double.parseDouble(product_price.getText().toString()));
                                                            productSpecificationOrAttributesData.setOne_this_product_discount(0);
                                                        }
                                                        productSpecificationOrAttributesData.setProduct_pic(product_data.get(category_name).get(finalJ).product_pic);
                                                        product_second_data.put(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp, productSpecificationOrAttributesData);
                                                    }
                                                }
                                                else {
                                                    if (!product_second_data.containsKey(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp)) {
                                                        Product_Specification_Or_Attributes_Data productSpecificationOrAttributesData = new Product_Specification_Or_Attributes_Data();
                                                        productSpecificationOrAttributesData.setMain_name(product_data.get(category_name).get(finalJ).product_name);
                                                        productSpecificationOrAttributesData.setSpecification_or_attributes(last_specification_text_view.getText().toString() + "，" + attributes_temp);
                                                        productSpecificationOrAttributesData.setHow_many(0);
                                                        productSpecificationOrAttributesData.setThis_product_has_how_many_discount_product(0);
                                                        if (set_discount_data.containsKey(product_data.get(category_name).get(finalJ).product_name)) {
                                                            productSpecificationOrAttributesData.setOne_this_product_original_price(Double.parseDouble(original_price.getText().toString().substring(1)));
                                                            productSpecificationOrAttributesData.setOne_this_product_discount(Double.parseDouble(product_price.getText().toString()));
                                                        }
                                                        else {
                                                            productSpecificationOrAttributesData.setOne_this_product_original_price(Double.parseDouble(product_price.getText().toString()));
                                                            productSpecificationOrAttributesData.setOne_this_product_discount(0);
                                                        }
                                                        productSpecificationOrAttributesData.setProduct_pic(product_data.get(category_name).get(finalJ).product_pic);
                                                        product_second_data.put(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp, productSpecificationOrAttributesData);
                                                    }
                                                }

                                                if (set_discount_data.containsKey(product_data.get(category_name).get(finalJ).product_name)) {
                                                    if (set_discount_data.get(product_data.get(category_name).get(finalJ).product_name).is_purchase_limit_in_order == 1) {
                                                        if (Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase) > 1 && choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) == 0) {
                                                            if (Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase) >= set_discount_data.get(product_data.get(category_name).get(finalJ).product_name).set_order_purchase_limit) {
                                                                how_many_dollars += (Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase) - set_discount_data.get(product_data.get(category_name).get(finalJ).product_name).set_order_purchase_limit) * Double.parseDouble(original_price.getText().toString().substring(1));
                                                                if (specification_name.isEmpty()) {
                                                                    product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).setHow_many(Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase));
                                                                    product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).setThis_product_has_how_many_discount_product(set_discount_data.get(product_data.get(category_name).get(finalJ).product_name).set_order_purchase_limit);
                                                                }
                                                                else {
                                                                    product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).setHow_many(Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase));
                                                                    product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).setThis_product_has_how_many_discount_product(set_discount_data.get(product_data.get(category_name).get(finalJ).product_name).set_order_purchase_limit);
                                                                }
                                                            }
                                                            else {
                                                                if (specification_name.isEmpty()) {
                                                                    product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).setHow_many(Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase));
                                                                    product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).setThis_product_has_how_many_discount_product(Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase));
                                                                }
                                                                else {
                                                                    product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).setHow_many(Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase));
                                                                    product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).setThis_product_has_how_many_discount_product(Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase));
                                                                }
                                                            }
                                                            how_many_dollars += set_discount_data.get(product_data.get(category_name).get(finalJ).product_name).set_order_purchase_limit * Double.parseDouble(product_price.getText().toString());
                                                            reduce_how_many_dollars += set_discount_data.get(product_data.get(category_name).get(finalJ).product_name).set_order_purchase_limit * (Double.parseDouble(original_price.getText().toString().substring(1)) - Double.parseDouble(product_price.getText().toString()));
                                                        } else {
                                                            if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) + 1 > set_discount_data.get(product_data.get(category_name).get(finalJ).product_name).set_order_purchase_limit) {
                                                                how_many_dollars += Double.parseDouble(original_price.getText().toString().substring(1));
                                                                if (specification_name.isEmpty()) {
                                                                    product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).getHow_many() + 1);
                                                                }
                                                                else {
                                                                    product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).getHow_many() + 1);
                                                                }
                                                            } else {
                                                                if (specification_name.isEmpty()) {
                                                                    product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).getHow_many() + 1);
                                                                    product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).setThis_product_has_how_many_discount_product(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).getThis_product_has_how_many_discount_product() + 1);
                                                                }
                                                                else {
                                                                    product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).getHow_many() + 1);
                                                                    product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).setThis_product_has_how_many_discount_product(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).getThis_product_has_how_many_discount_product() + 1);
                                                                }
                                                                how_many_dollars += Double.parseDouble(product_price.getText().toString());
                                                                reduce_how_many_dollars += (Double.parseDouble(original_price.getText().toString().substring(1)) - Double.parseDouble(product_price.getText().toString()));
                                                            }
                                                        }
                                                    } else {
                                                        if (specification_name.isEmpty()) {
                                                            product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).getHow_many() + 1);
                                                            product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).setThis_product_has_how_many_discount_product(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).getThis_product_has_how_many_discount_product() + 1);
                                                        }
                                                        else {
                                                            product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).getHow_many() + 1);
                                                            product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).setThis_product_has_how_many_discount_product(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).getThis_product_has_how_many_discount_product() + 1);
                                                        }
                                                        how_many_dollars += Double.parseDouble(product_price.getText().toString());
                                                        reduce_how_many_dollars += Double.parseDouble(original_price.getText().toString().substring(1)) - Double.parseDouble(product_price.getText().toString());
                                                    }
                                                } else {
                                                    if (Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase) > 1 && choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) == 0) {
                                                        how_many_dollars += Double.parseDouble(product_price.getText().toString()) * Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase);
                                                        if (specification_name.isEmpty()) {
                                                            product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).setHow_many(Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase));
                                                        }
                                                        else {
                                                            product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).setHow_many(Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase));
                                                        }
                                                    } else {
                                                        how_many_dollars += Double.parseDouble(product_price.getText().toString());
                                                        if (specification_name.isEmpty()) {
                                                            product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).getHow_many() + 1);
                                                        }
                                                        else {
                                                            product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).getHow_many() + 1);
                                                        }
                                                    }
                                                }

                                                if (Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase) > 1) {
                                                    if (specification_name.isEmpty()) {
                                                        if (!choose_how_many_product.containsKey(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp)) {
                                                            if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) == 0) {
                                                                choose_how_many_product.put(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp, Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase));
                                                                choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name, Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase));
                                                                buy_how_many_product += Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase);
                                                            } else {
                                                                choose_how_many_product.put(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp, 1);
                                                                choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name, choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) + 1);
                                                                buy_how_many_product += 1;
                                                            }
                                                        } else {
                                                            if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) == 0) {
                                                                choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp, Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase));
                                                                choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name, Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase));
                                                                buy_how_many_product += Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase);
                                                            } else {
                                                                choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp, choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp) + 1);
                                                                choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name, choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) + 1);
                                                                buy_how_many_product += 1;
                                                            }
                                                        }
                                                    } else {
                                                        if (!choose_how_many_product.containsKey(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp)) {
                                                            if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) == 0) {
                                                                choose_how_many_product.put(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp, Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase));
                                                                choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name, Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase));
                                                                buy_how_many_product += Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase);
                                                            } else {
                                                                choose_how_many_product.put(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp, 1);
                                                                choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name, choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) + 1);
                                                                buy_how_many_product += 1;
                                                            }
                                                        } else {
                                                            if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) == 0) {
                                                                choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp, Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase));
                                                                choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name, Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase));
                                                                buy_how_many_product += Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase);
                                                            } else {
                                                                choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp, choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp) + 1);
                                                                choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name, choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) + 1);
                                                                buy_how_many_product += 1;
                                                            }
                                                        }
                                                    }
                                                } else {
                                                    if (specification_name.isEmpty()) {
                                                        if (!choose_how_many_product.containsKey(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp)) {
                                                            choose_how_many_product.put(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp, 1);
                                                            choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name, choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) + 1);
                                                        } else {
                                                            choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp, choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp) + 1);
                                                            choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name, choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) + 1);
                                                        }
                                                    } else {
                                                        if (!choose_how_many_product.containsKey(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp)) {
                                                            choose_how_many_product.put(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp, 1);
                                                            choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name, choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) + 1);
                                                        } else {
                                                            choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp, choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp) + 1);
                                                            choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name, choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) + 1);
                                                        }
                                                    }
                                                    buy_how_many_product += 1;
                                                }
                                                is_set_min_purchase.setText("+");
                                                how_many_in_this_product.setVisibility(View.VISIBLE);
                                                delete_specification_or_attributes.setVisibility(View.VISIBLE);
                                                if (specification_name.isEmpty()) {
                                                    how_many_in_this_product.setText(choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp) + "");
                                                } else {
                                                    how_many_in_this_product.setText(choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp) + "");
                                                }

                                                if (product_data.get(category_name).get(finalJ).is_single_order_without_delivery.equals("1")) {
                                                    how_many_single_order_without_delivery.replace(true, how_many_single_order_without_delivery.get(true) + 1);
                                                } else {
                                                    how_many_single_order_without_delivery.replace(false, how_many_single_order_without_delivery.get(false) + 1);
                                                }

                                                if (how_many_single_order_without_delivery.get(false) > 0) {
                                                    go_to_check_page.setText("去结算");
                                                    go_to_check_page.setEnabled(true);
                                                    go_to_check_page.setBackgroundColor(Color.YELLOW);
                                                    go_to_check_page.setTextColor(Color.BLACK);
                                                } else {
                                                    go_to_check_page.setText("单点不送");
                                                    go_to_check_page.setEnabled(false);
                                                    go_to_check_page.setBackgroundColor(Color.rgb(211, 211, 211));
                                                    go_to_check_page.setTextColor(Color.WHITE);
                                                }

                                                how_many_in_this_product_in_has_specification_or_attributes.setVisibility(View.VISIBLE);
                                                how_many_in_this_product_in_has_specification_or_attributes.setText("" + choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name));
                                                reduce_how_many_money.setText("" + String.format("%.2f", Math.abs(reduce_how_many_dollars)));
                                                should_pay_how_much.setText("" + String.format("%.2f", Math.abs(how_many_dollars)));
                                                how_many_product.setText("" + buy_how_many_product);
                                            }
                                        });

                                        delete_specification_or_attributes.setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                String attributes_temp = "";
                                                for (int i = 0; i < last_attributes_text_view_list.size(); i++) {
                                                    attributes_temp += last_attributes_text_view_list.get(i).getText().toString();
                                                    attributes_temp += "，";
                                                }
                                                if (Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase) > 1) {
                                                    if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) == Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase)) {
                                                        if (specification_name.isEmpty()) {
                                                            choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp, 0);
                                                        } else {
                                                            choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp, 0);
                                                        }
                                                        choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name, 0);
                                                        is_set_min_purchase.setText("+" + product_data.get(category_name).get(finalJ).min_purchase + "份起购");
                                                        delete_specification_or_attributes.setVisibility(View.GONE);
                                                        how_many_in_this_product.setText("0");
                                                        how_many_in_this_product.setVisibility(View.GONE);
                                                        buy_how_many_product -= Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase);
                                                    } else {
                                                        if (specification_name.isEmpty()) {
                                                            choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp, choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp) - 1);
                                                            if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp) == 0) {
                                                                is_set_min_purchase.setText("+加入购物车");
                                                                delete_specification_or_attributes.setVisibility(View.GONE);
                                                                how_many_in_this_product.setText("0");
                                                                how_many_in_this_product.setVisibility(View.GONE);
                                                            } else {
                                                                how_many_in_this_product.setText("" + choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp));
                                                            }
                                                        } else {
                                                            choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp, choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp) - 1);
                                                            if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp) == 0) {
                                                                is_set_min_purchase.setText("+加入购物车");
                                                                delete_specification_or_attributes.setVisibility(View.GONE);
                                                                how_many_in_this_product.setText("0");
                                                                how_many_in_this_product.setVisibility(View.GONE);
                                                            } else {
                                                                how_many_in_this_product.setText("" + choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp));
                                                            }
                                                        }
                                                        buy_how_many_product -= 1;
                                                        choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name, choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) - 1);
                                                    }
                                                } else {
                                                    if (specification_name.isEmpty()) {
                                                        choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp, choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp) - 1);
                                                        if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp) == 0) {
                                                            is_set_min_purchase.setText("+加入购物车");
                                                            delete_specification_or_attributes.setVisibility(View.GONE);
                                                            how_many_in_this_product.setText("0");
                                                            how_many_in_this_product.setVisibility(View.GONE);
                                                        } else {
                                                            how_many_in_this_product.setText("" + choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp));
                                                        }
                                                    } else {
                                                        choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp, choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp) - 1);
                                                        if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp) == 0) {
                                                            is_set_min_purchase.setText("+加入购物车");
                                                            delete_specification_or_attributes.setVisibility(View.GONE);
                                                            how_many_in_this_product.setText("0");
                                                            how_many_in_this_product.setVisibility(View.GONE);
                                                        } else {
                                                            how_many_in_this_product.setText("" + choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp));
                                                        }
                                                    }
                                                    buy_how_many_product -= 1;
                                                    choose_how_many_product.replace(product_data.get(category_name).get(finalJ).product_name, choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) - 1);
                                                }

                                                if (set_discount_data.containsKey(product_data.get(category_name).get(finalJ).product_name)) {
                                                    if (set_discount_data.get(product_data.get(category_name).get(finalJ).product_name).is_purchase_limit_in_order == 1) {
                                                        if (Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase) > 1 && choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) == 0) {
                                                            how_many_dollars -= (Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase) - set_discount_data.get(product_data.get(category_name).get(finalJ).product_name).set_order_purchase_limit) * Double.parseDouble(product_data.get(category_name).get(finalJ).product_price);
                                                            how_many_dollars -= set_discount_data.get(product_data.get(category_name).get(finalJ).product_name).set_order_purchase_limit * set_discount_data.get(product_data.get(category_name).get(finalJ).product_name).discount_price;
                                                            reduce_how_many_dollars -= set_discount_data.get(product_data.get(category_name).get(finalJ).product_name).set_order_purchase_limit * (Double.parseDouble(product_data.get(category_name).get(finalJ).product_price) - set_discount_data.get(product_data.get(category_name).get(finalJ).product_name).discount_price);
                                                            for (Iterator<Map.Entry<String, Product_Specification_Or_Attributes_Data>> it = product_second_data.entrySet().iterator(); it.hasNext();){
                                                                Map.Entry<String, Product_Specification_Or_Attributes_Data> item = it.next();
                                                                if (product_second_data.get(item.getKey()).getMain_name().equals(product_data.get(category_name).get(finalJ).product_name)) {
                                                                    it.remove();
                                                                }
                                                            }
                                                        } else {
                                                            if (specification_name.isEmpty()) {
                                                                if (product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).getHow_many() > product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).getThis_product_has_how_many_discount_product()) {
                                                                    how_many_dollars -= Double.parseDouble(original_price.getText().toString().substring(1));
                                                                    product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).getHow_many() - 1);
                                                                }
                                                                else {
                                                                    for (String key : product_second_data.keySet()) {
                                                                        if (product_second_data.get(key).getMain_name().equals(product_data.get(category_name).get(finalJ).product_name)) {
                                                                            if (product_second_data.get(key).getThis_product_has_how_many_discount_product() < product_second_data.get(key).getHow_many()) {
                                                                                product_second_data.get(key).setThis_product_has_how_many_discount_product(product_second_data.get(key).getThis_product_has_how_many_discount_product() + 1);
                                                                                how_many_dollars -= (product_second_data.get(key).getOne_this_product_original_price() - product_second_data.get(key).getOne_this_product_discount());
                                                                                reduce_how_many_dollars += (product_second_data.get(key).getOne_this_product_original_price() - product_second_data.get(key).getOne_this_product_discount());
                                                                            }
                                                                        }
                                                                    }
                                                                    how_many_dollars -= Double.parseDouble(product_price.getText().toString());
                                                                    reduce_how_many_dollars -= Double.parseDouble(original_price.getText().toString().substring(1)) - Double.parseDouble(product_price.getText().toString());
                                                                    product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).setThis_product_has_how_many_discount_product(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).getThis_product_has_how_many_discount_product() - 1);
                                                                    product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).getHow_many() - 1);
                                                                }
                                                            }
                                                            else {
                                                                if (product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).getHow_many() > product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).getThis_product_has_how_many_discount_product()) {
                                                                    how_many_dollars -= Double.parseDouble(original_price.getText().toString().substring(1));
                                                                    product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).getHow_many() - 1);
                                                                }
                                                                else {
                                                                    for (String key : product_second_data.keySet()) {
                                                                        if (product_second_data.get(key).getMain_name().equals(product_data.get(category_name).get(finalJ).product_name)) {
                                                                            if (product_second_data.get(key).getThis_product_has_how_many_discount_product() < product_second_data.get(key).getHow_many()) {
                                                                                product_second_data.get(key).setThis_product_has_how_many_discount_product(product_second_data.get(key).getThis_product_has_how_many_discount_product() + 1);
                                                                                how_many_dollars -= (product_second_data.get(key).getOne_this_product_original_price() - product_second_data.get(key).getOne_this_product_discount());
                                                                                reduce_how_many_dollars += (product_second_data.get(key).getOne_this_product_original_price() - product_second_data.get(key).getOne_this_product_discount());
                                                                            }
                                                                        }
                                                                    }
                                                                    how_many_dollars -= Double.parseDouble(product_price.getText().toString());
                                                                    reduce_how_many_dollars -= Double.parseDouble(original_price.getText().toString().substring(1)) - Double.parseDouble(product_price.getText().toString());
                                                                    product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).setThis_product_has_how_many_discount_product(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).getThis_product_has_how_many_discount_product() - 1);
                                                                    product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).getHow_many() - 1);
                                                                }
                                                            }
                                                        }
                                                    } else {
                                                        how_many_dollars -= Double.parseDouble(product_price.getText().toString());
                                                        reduce_how_many_dollars -= Double.parseDouble(original_price.getText().toString().substring(1)) - Double.parseDouble(product_price.getText().toString());
                                                        if (specification_name.isEmpty()) {
                                                            product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).setThis_product_has_how_many_discount_product(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).getThis_product_has_how_many_discount_product() - 1);
                                                            product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).getHow_many() - 1);
                                                        }
                                                        else {
                                                            product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).setThis_product_has_how_many_discount_product(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).getThis_product_has_how_many_discount_product() - 1);
                                                            product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).getHow_many() - 1);
                                                        }
                                                    }
                                                } else {
                                                    if (Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase) > 1 && choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) == 0) {
                                                        how_many_dollars -= Double.parseDouble(product_price.getText().toString()) * Integer.parseInt(product_data.get(category_name).get(finalJ).min_purchase);
                                                        for (Iterator<Map.Entry<String, Product_Specification_Or_Attributes_Data>> it = product_second_data.entrySet().iterator(); it.hasNext();){
                                                            Map.Entry<String, Product_Specification_Or_Attributes_Data> item = it.next();
                                                            if (product_second_data.get(item.getKey()).getMain_name().equals(product_data.get(category_name).get(finalJ).product_name)) {
                                                                it.remove();
                                                            }
                                                        }
                                                    } else {
                                                        how_many_dollars -= Double.parseDouble(product_price.getText().toString());
                                                        if (specification_name.isEmpty()) {
                                                            product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + attributes_temp).getHow_many() - 1);
                                                        }
                                                        else {
                                                            product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ).product_name + "，" + last_specification_text_view.getText().toString() + "，" + attributes_temp).getHow_many() - 1);
                                                        }
                                                    }
                                                }

                                                if (buy_how_many_product == 0) {
                                                    AnimationSet animationSet = (AnimationSet) AnimationUtils.loadAnimation(Check_Shop_Data_Page.this, R.anim.close_check_out_bottom);
                                                    set_check_out_dialog.startAnimation(animationSet);
                                                    set_check_out_dialog.setVisibility(View.GONE);
                                                    is_show_check_out_bottom = false;
                                                }

                                                if (choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name) == 0) {
                                                    how_many_in_this_product_in_has_specification_or_attributes.setVisibility(View.GONE);
                                                }

                                                if (product_data.get(category_name).get(finalJ).is_single_order_without_delivery.equals("1")) {
                                                    how_many_single_order_without_delivery.replace(true, how_many_single_order_without_delivery.get(true) - 1);
                                                } else {
                                                    how_many_single_order_without_delivery.replace(false, how_many_single_order_without_delivery.get(false) - 1);
                                                }

                                                if (how_many_single_order_without_delivery.get(false) > 0) {
                                                    go_to_check_page.setText("去结算");
                                                    go_to_check_page.setEnabled(true);
                                                    go_to_check_page.setBackgroundColor(Color.YELLOW);
                                                    go_to_check_page.setTextColor(Color.BLACK);
                                                } else {
                                                    go_to_check_page.setText("单点不送");
                                                    go_to_check_page.setEnabled(false);
                                                    go_to_check_page.setBackgroundColor(Color.rgb(211, 211, 211));
                                                    go_to_check_page.setTextColor(Color.WHITE);
                                                }

                                                how_many_in_this_product_in_has_specification_or_attributes.setText("" + choose_how_many_product.get(product_data.get(category_name).get(finalJ).product_name));
                                                reduce_how_many_money.setText("" + String.format("%.2f", Math.abs(reduce_how_many_dollars)));
                                                should_pay_how_much.setText("" + String.format("%.2f", Math.abs(how_many_dollars)));
                                                how_many_product.setText("" + buy_how_many_product);
                                            }
                                        });

                                        dialog.show();
                                        dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                                        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                                        dialog.getWindow().getAttributes().windowAnimations = R.style.Show_Specification_Animation;
                                        dialog.getWindow().setGravity(Gravity.CENTER);
                                    }
                                });
                            } else if (Integer.parseInt(product_data.get(category_name).get(j).min_purchase) > 1) {
                                is_specification_or_attributes.setText(product_data.get(category_name).get(j).min_purchase + "份起购");
                                int finalJ1 = j;
                                choose_specification_or_attributes.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        if (!is_show_check_out_bottom) {
                                            AnimationSet animationSet = (AnimationSet) AnimationUtils.loadAnimation(Check_Shop_Data_Page.this, R.anim.show_check_out_bottom);
                                            set_check_out_dialog.startAnimation(animationSet);
                                            set_check_out_dialog.setVisibility(View.VISIBLE);
                                            is_show_check_out_bottom = true;
                                        }

                                        if (!product_second_data.containsKey(product_data.get(category_name).get(finalJ1).product_name)) {
                                            Product_Specification_Or_Attributes_Data productSpecificationOrAttributesData = new Product_Specification_Or_Attributes_Data();
                                            productSpecificationOrAttributesData.setMain_name(product_data.get(category_name).get(finalJ1).product_name);
                                            productSpecificationOrAttributesData.setSpecification_or_attributes("");
                                            productSpecificationOrAttributesData.setHow_many(0);
                                            productSpecificationOrAttributesData.setThis_product_has_how_many_discount_product(0);
                                            if (set_discount_data.containsKey(product_data.get(category_name).get(finalJ1).product_name)) {
                                                productSpecificationOrAttributesData.setOne_this_product_original_price(set_discount_data.get(product_data.get(category_name).get(finalJ1).product_name).discount_price);
                                                productSpecificationOrAttributesData.setOne_this_product_discount(Double.parseDouble(product_data.get(category_name).get(finalJ1).product_price));
                                            }
                                            else {
                                                productSpecificationOrAttributesData.setOne_this_product_original_price(Double.parseDouble(product_data.get(category_name).get(finalJ1).product_price));
                                                productSpecificationOrAttributesData.setOne_this_product_discount(0);
                                            }
                                            productSpecificationOrAttributesData.setProduct_pic(product_data.get(category_name).get(finalJ1).product_pic);
                                            product_second_data.put(product_data.get(category_name).get(finalJ1).product_name, productSpecificationOrAttributesData);
                                        }

                                        if (set_discount_data.containsKey(product_data.get(category_name).get(finalJ1).product_name)) {
                                            if (set_discount_data.get(product_data.get(category_name).get(finalJ1).product_name).is_purchase_limit_in_order == 1) {
                                                if (Integer.parseInt(product_data.get(category_name).get(finalJ1).min_purchase) > 1 && choose_how_many_product.get(product_data.get(category_name).get(finalJ1).product_name) == 0) {
                                                    if (Integer.parseInt(product_data.get(category_name).get(finalJ1).min_purchase) >= set_discount_data.get(product_data.get(category_name).get(finalJ1).product_name).set_order_purchase_limit) {
                                                        how_many_dollars += (Integer.parseInt(product_data.get(category_name).get(finalJ1).min_purchase) - set_discount_data.get(product_data.get(category_name).get(finalJ1).product_name).set_order_purchase_limit) * Double.parseDouble(product_data.get(category_name).get(finalJ1).product_price);
                                                    }
                                                    product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).setHow_many(Integer.parseInt(product_data.get(category_name).get(finalJ1).min_purchase));
                                                    product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).setThis_product_has_how_many_discount_product(set_discount_data.get(product_data.get(category_name).get(finalJ1).product_name).set_order_purchase_limit);
                                                    how_many_dollars += set_discount_data.get(product_data.get(category_name).get(finalJ1).product_name).set_order_purchase_limit * set_discount_data.get(product_data.get(category_name).get(finalJ1).product_name).discount_price;
                                                    reduce_how_many_dollars += set_discount_data.get(product_data.get(category_name).get(finalJ1).product_name).set_order_purchase_limit * (Double.parseDouble(product_data.get(category_name).get(finalJ1).product_price) - set_discount_data.get(product_data.get(category_name).get(finalJ1).product_name).discount_price);
                                                } else {
                                                    if (Integer.parseInt(how_many_in_this_product.getText().toString()) + 1 > set_discount_data.get(product_data.get(category_name).get(finalJ1).product_name).set_order_purchase_limit) {
                                                        how_many_dollars += Double.parseDouble(product_data.get(category_name).get(finalJ1).product_price);
                                                    } else {
                                                        how_many_dollars += set_discount_data.get(product_data.get(category_name).get(finalJ1).product_name).discount_price;
                                                        reduce_how_many_dollars += (Double.parseDouble(product_data.get(category_name).get(finalJ1).product_price) - set_discount_data.get(product_data.get(category_name).get(finalJ1).product_name).discount_price);
                                                        product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).setThis_product_has_how_many_discount_product(product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).getThis_product_has_how_many_discount_product() + 1);
                                                    }
                                                    product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).getHow_many() + 1);
                                                }
                                            } else {
                                                how_many_dollars += set_discount_data.get(product_data.get(category_name).get(finalJ1).product_name).discount_price;
                                                reduce_how_many_dollars += (Double.parseDouble(product_data.get(category_name).get(finalJ1).product_price) - set_discount_data.get(product_data.get(category_name).get(finalJ1).product_name).discount_price);
                                                product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).getHow_many() + 1);
                                                product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).setThis_product_has_how_many_discount_product(product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).getThis_product_has_how_many_discount_product() + 1);
                                            }
                                        } else {
                                            if (Integer.parseInt(product_data.get(category_name).get(finalJ1).min_purchase) > 1 && choose_how_many_product.get(product_data.get(category_name).get(finalJ1).product_name) == 0) {
                                                how_many_dollars += Double.parseDouble(product_data.get(category_name).get(finalJ1).product_price) * Integer.parseInt(product_data.get(category_name).get(finalJ1).min_purchase);
                                                product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).setHow_many(Integer.parseInt(product_data.get(category_name).get(finalJ1).min_purchase));
                                            } else {
                                                how_many_dollars += Double.parseDouble(product_data.get(category_name).get(finalJ1).product_price);
                                                product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).getHow_many() + 1);
                                            }
                                        }

                                        if (choose_how_many_product.get(product_data.get(category_name).get(finalJ1).product_name) == 0) {
                                            choose_how_many_product.replace(product_data.get(category_name).get(finalJ1).product_name, Integer.parseInt(product_data.get(category_name).get(finalJ1).min_purchase));
                                            buy_how_many_product += Integer.parseInt(product_data.get(category_name).get(finalJ1).min_purchase);
                                            is_specification_or_attributes.setText("+");
                                        } else {
                                            choose_how_many_product.replace(product_data.get(category_name).get(finalJ1).product_name, choose_how_many_product.get(product_data.get(category_name).get(finalJ1).product_name) + 1);
                                            buy_how_many_product += 1;
                                        }

                                        if (product_data.get(category_name).get(finalJ1).is_single_order_without_delivery.equals("1")) {
                                            how_many_single_order_without_delivery.replace(true, how_many_single_order_without_delivery.get(true) + 1);
                                        } else {
                                            how_many_single_order_without_delivery.replace(false, how_many_single_order_without_delivery.get(false) + 1);
                                        }

                                        if (how_many_single_order_without_delivery.get(false) > 0) {
                                            go_to_check_page.setText("去结算");
                                            go_to_check_page.setEnabled(true);
                                            go_to_check_page.setBackgroundColor(Color.YELLOW);
                                            go_to_check_page.setTextColor(Color.BLACK);
                                        } else {
                                            go_to_check_page.setText("单点不送");
                                            go_to_check_page.setEnabled(false);
                                            go_to_check_page.setBackgroundColor(Color.rgb(211, 211, 211));
                                            go_to_check_page.setTextColor(Color.WHITE);
                                        }

                                        how_many_in_this_product.setVisibility(View.VISIBLE);
                                        how_many_in_this_product.setText("" + choose_how_many_product.get(product_data.get(category_name).get(finalJ1).product_name));
                                        delete_specification_or_attributes.setVisibility(View.VISIBLE);
                                        how_many_product.setText("" + buy_how_many_product);
                                        should_pay_how_much.setText("" + String.format("%.2f", Math.abs(how_many_dollars)));
                                        reduce_how_many_money.setText("" + String.format("%.2f", Math.abs(reduce_how_many_dollars)));
                                    }
                                });
                            } else {
                                is_specification_or_attributes.setText("+");
                                int finalJ1 = j;
                                choose_specification_or_attributes.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        if (!is_show_check_out_bottom) {
                                            AnimationSet animationSet = (AnimationSet) AnimationUtils.loadAnimation(Check_Shop_Data_Page.this, R.anim.show_check_out_bottom);
                                            set_check_out_dialog.startAnimation(animationSet);
                                            set_check_out_dialog.setVisibility(View.VISIBLE);
                                            is_show_check_out_bottom = true;
                                        }

                                        choose_how_many_product.replace(product_data.get(category_name).get(finalJ1).product_name, choose_how_many_product.get(product_data.get(category_name).get(finalJ1).product_name) + 1);

                                        if (!product_second_data.containsKey(product_data.get(category_name).get(finalJ1).product_name)) {
                                            Product_Specification_Or_Attributes_Data productSpecificationOrAttributesData = new Product_Specification_Or_Attributes_Data();
                                            productSpecificationOrAttributesData.setMain_name(product_data.get(category_name).get(finalJ1).product_name);
                                            productSpecificationOrAttributesData.setSpecification_or_attributes("");
                                            productSpecificationOrAttributesData.setHow_many(0);
                                            productSpecificationOrAttributesData.setThis_product_has_how_many_discount_product(0);
                                            if (set_discount_data.containsKey(product_data.get(category_name).get(finalJ1).product_name)) {
                                                productSpecificationOrAttributesData.setOne_this_product_discount(set_discount_data.get(product_data.get(category_name).get(finalJ1).product_name).discount_price);
                                                productSpecificationOrAttributesData.setOne_this_product_original_price(Double.parseDouble(product_data.get(category_name).get(finalJ1).product_price));
                                            }
                                            else {
                                                productSpecificationOrAttributesData.setOne_this_product_original_price(Double.parseDouble(product_data.get(category_name).get(finalJ1).product_price));
                                                productSpecificationOrAttributesData.setOne_this_product_discount(0);
                                            }
                                            productSpecificationOrAttributesData.setProduct_pic(product_data.get(category_name).get(finalJ1).product_pic);
                                            product_second_data.put(product_data.get(category_name).get(finalJ1).product_name, productSpecificationOrAttributesData);
                                        }

                                        if (set_discount_data.containsKey(product_data.get(category_name).get(finalJ1).product_name)) {
                                            if (set_discount_data.get(product_data.get(category_name).get(finalJ1).product_name).is_purchase_limit_in_order == 1) {
                                                if (Integer.parseInt(how_many_in_this_product.getText().toString()) + 1 > set_discount_data.get(product_data.get(category_name).get(finalJ1).product_name).set_order_purchase_limit) {
                                                    how_many_dollars += Double.parseDouble(product_data.get(category_name).get(finalJ1).product_price);
                                                } else {
                                                    how_many_dollars += set_discount_data.get(product_data.get(category_name).get(finalJ1).product_name).discount_price;
                                                    reduce_how_many_dollars += (Double.parseDouble(product_data.get(category_name).get(finalJ1).product_price) - set_discount_data.get(product_data.get(category_name).get(finalJ1).product_name).discount_price);
                                                    product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).setThis_product_has_how_many_discount_product(product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).getThis_product_has_how_many_discount_product() + 1);
                                                }
                                                product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).getHow_many() + 1);
                                            } else {
                                                how_many_dollars += set_discount_data.get(product_data.get(category_name).get(finalJ1).product_name).discount_price;
                                                reduce_how_many_dollars += (Double.parseDouble(product_data.get(category_name).get(finalJ1).product_price) - set_discount_data.get(product_data.get(category_name).get(finalJ1).product_name).discount_price);
                                                product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).setThis_product_has_how_many_discount_product(product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).getThis_product_has_how_many_discount_product() + 1);
                                                product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).getHow_many() + 1);
                                            }
                                        } else {
                                            how_many_dollars += Double.parseDouble(product_data.get(category_name).get(finalJ1).product_price);
                                            product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ1).product_name).getHow_many() + 1);
                                        }

                                        if (product_data.get(category_name).get(finalJ1).is_single_order_without_delivery.equals("1")) {
                                            how_many_single_order_without_delivery.replace(true, how_many_single_order_without_delivery.get(true) + 1);
                                        } else {
                                            how_many_single_order_without_delivery.replace(false, how_many_single_order_without_delivery.get(false) + 1);
                                        }

                                        if (how_many_single_order_without_delivery.get(false) > 0) {
                                            go_to_check_page.setText("去结算");
                                            go_to_check_page.setEnabled(true);
                                            go_to_check_page.setBackgroundColor(Color.YELLOW);
                                            go_to_check_page.setTextColor(Color.BLACK);
                                        } else {
                                            go_to_check_page.setText("单点不送");
                                            go_to_check_page.setEnabled(false);
                                            go_to_check_page.setBackgroundColor(Color.rgb(211, 211, 211));
                                            go_to_check_page.setTextColor(Color.WHITE);
                                        }

                                        how_many_in_this_product.setVisibility(View.VISIBLE);
                                        how_many_in_this_product.setText("" + choose_how_many_product.get(product_data.get(category_name).get(finalJ1).product_name));
                                        delete_specification_or_attributes.setVisibility(View.VISIBLE);
                                        buy_how_many_product += 1;
                                        how_many_product.setText("" + buy_how_many_product);
                                        should_pay_how_much.setText("" + String.format("%.2f", Math.abs(how_many_dollars)));
                                        reduce_how_many_money.setText("" + String.format("%.2f", Math.abs(reduce_how_many_dollars)));
                                    }
                                });
                            }

                            int finalJ2 = j;
                            delete_specification_or_attributes.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    if (Integer.parseInt(product_data.get(category_name).get(finalJ2).min_purchase) > 1 && choose_how_many_product.get(product_data.get(category_name).get(finalJ2).product_name) == Integer.parseInt(product_data.get(category_name).get(finalJ2).min_purchase)) {
                                        choose_how_many_product.replace(product_data.get(category_name).get(finalJ2).product_name, 0);
                                        buy_how_many_product -= Integer.parseInt(product_data.get(category_name).get(finalJ2).min_purchase);
                                        is_specification_or_attributes.setText(product_data.get(category_name).get(finalJ2).min_purchase + "份起购");
                                    } else {
                                        choose_how_many_product.replace(product_data.get(category_name).get(finalJ2).product_name, choose_how_many_product.get(product_data.get(category_name).get(finalJ2).product_name) - 1);
                                        buy_how_many_product -= 1;
                                    }
                                    if (choose_how_many_product.get(product_data.get(category_name).get(finalJ2).product_name) == 0) {
                                        how_many_in_this_product.setVisibility(View.GONE);
                                        how_many_in_this_product.setText("0");
                                        delete_specification_or_attributes.setVisibility(View.GONE);
                                    } else {
                                        how_many_in_this_product.setText("" + choose_how_many_product.get(product_data.get(category_name).get(finalJ2).product_name));
                                    }

                                    if (set_discount_data.containsKey(product_data.get(category_name).get(finalJ2).product_name)) {
                                        if (set_discount_data.get(product_data.get(category_name).get(finalJ2).product_name).is_purchase_limit_in_order == 1) {
                                            if (Integer.parseInt(product_data.get(category_name).get(finalJ2).min_purchase) > 1 && choose_how_many_product.get(product_data.get(category_name).get(finalJ2).product_name) == 0) {
                                                how_many_dollars -= (Integer.parseInt(product_data.get(category_name).get(finalJ2).min_purchase) - set_discount_data.get(product_data.get(category_name).get(finalJ2).product_name).set_order_purchase_limit) * Double.parseDouble(product_data.get(category_name).get(finalJ2).product_price);
                                                how_many_dollars -= set_discount_data.get(product_data.get(category_name).get(finalJ2).product_name).set_order_purchase_limit * set_discount_data.get(product_data.get(category_name).get(finalJ2).product_name).discount_price;
                                                reduce_how_many_dollars -= set_discount_data.get(product_data.get(category_name).get(finalJ2).product_name).set_order_purchase_limit * (Double.parseDouble(product_data.get(category_name).get(finalJ2).product_price) - set_discount_data.get(product_data.get(category_name).get(finalJ2).product_name).discount_price);
                                                product_second_data.remove(product_data.get(category_name).get(finalJ2).product_name);
                                            } else {
                                                if (product_second_data.get(product_data.get(category_name).get(finalJ2).product_name).getHow_many() > product_second_data.get(product_data.get(category_name).get(finalJ2).product_name).getThis_product_has_how_many_discount_product()) {
                                                    how_many_dollars -= Double.parseDouble(product_data.get(category_name).get(finalJ2).product_price);
                                                    product_second_data.get(product_data.get(category_name).get(finalJ2).product_name).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ2).product_name).getHow_many() - 1);
                                                }
                                                else {
                                                    how_many_dollars -= set_discount_data.get(product_data.get(category_name).get(finalJ2).product_name).discount_price;
                                                    product_second_data.get(product_data.get(category_name).get(finalJ2).product_name).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ2).product_name).getHow_many() - 1);
                                                    product_second_data.get(product_data.get(category_name).get(finalJ2).product_name).setThis_product_has_how_many_discount_product(product_second_data.get(product_data.get(category_name).get(finalJ2).product_name).getThis_product_has_how_many_discount_product() - 1);
                                                    reduce_how_many_dollars -= Double.parseDouble(product_data.get(category_name).get(finalJ2).product_price) - set_discount_data.get(product_data.get(category_name).get(finalJ2).product_name).discount_price;
                                                }
                                            }
                                        } else {
                                            how_many_dollars -= set_discount_data.get(product_data.get(category_name).get(finalJ2).product_name).discount_price;
                                            reduce_how_many_dollars -= (Double.parseDouble(product_data.get(category_name).get(finalJ2).product_price) - set_discount_data.get(product_data.get(category_name).get(finalJ2).product_name).discount_price);
                                            product_second_data.get(product_data.get(category_name).get(finalJ2).product_name).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ2).product_name).getHow_many() - 1);
                                            product_second_data.get(product_data.get(category_name).get(finalJ2).product_name).setThis_product_has_how_many_discount_product(product_second_data.get(product_data.get(category_name).get(finalJ2).product_name).getThis_product_has_how_many_discount_product() - 1);
                                        }
                                    } else {
                                        if (Integer.parseInt(product_data.get(category_name).get(finalJ2).min_purchase) > 1 && choose_how_many_product.get(product_data.get(category_name).get(finalJ2).product_name) == 0) {
                                            how_many_dollars -= Double.parseDouble(product_data.get(category_name).get(finalJ2).product_price) * Integer.parseInt(product_data.get(category_name).get(finalJ2).min_purchase);
                                            product_second_data.get(product_data.get(category_name).get(finalJ2).product_name).setHow_many(0);
                                        } else {
                                            how_many_dollars -= Double.parseDouble(product_data.get(category_name).get(finalJ2).product_price);
                                            product_second_data.get(product_data.get(category_name).get(finalJ2).product_name).setHow_many(product_second_data.get(product_data.get(category_name).get(finalJ2).product_name).getHow_many() - 1);
                                        }
                                    }

                                    if (buy_how_many_product == 0) {
                                        AnimationSet animationSet = (AnimationSet) AnimationUtils.loadAnimation(Check_Shop_Data_Page.this, R.anim.close_check_out_bottom);
                                        set_check_out_dialog.startAnimation(animationSet);
                                        set_check_out_dialog.setVisibility(View.GONE);
                                        is_show_check_out_bottom = false;
                                    }

                                    if (product_data.get(category_name).get(finalJ2).is_single_order_without_delivery.equals("1")) {
                                        how_many_single_order_without_delivery.replace(true, how_many_single_order_without_delivery.get(true) - 1);
                                    } else {
                                        how_many_single_order_without_delivery.replace(false, how_many_single_order_without_delivery.get(false) - 1);
                                    }

                                    if (how_many_single_order_without_delivery.get(false) > 0) {
                                        go_to_check_page.setText("去结算");
                                        go_to_check_page.setEnabled(true);
                                        go_to_check_page.setBackgroundColor(Color.YELLOW);
                                        go_to_check_page.setTextColor(Color.BLACK);
                                    } else {
                                        go_to_check_page.setText("单点不送");
                                        go_to_check_page.setEnabled(false);
                                        go_to_check_page.setBackgroundColor(Color.rgb(211, 211, 211));
                                        go_to_check_page.setTextColor(Color.WHITE);
                                    }

                                    reduce_how_many_money.setText("" + String.format("%.2f", Math.abs(reduce_how_many_dollars)));
                                    should_pay_how_much.setText("" + String.format("%.2f", Math.abs(how_many_dollars)));
                                    how_many_product.setText("" + buy_how_many_product);
                                }
                            });
                            product.addView(view3);
                        }
                    }
                    product_list_layout.addView(view2);
                    view_list.view = view2;
                    view_list.cardView = item;
                    viewList.add(view_list);
                    System.out.println(viewList.size());
                }
            });
        }
    }

    private class Category_Data_Thread extends Thread {

        LinearLayout set_category_layout, product_list_layout;
        ScrollView set_category_list_view, product_list_view;
        TextView is_in_bottom;
        ProgressBar is_loading;

        public Category_Data_Thread(LinearLayout set_category_layout, LinearLayout product_list_layout, ScrollView set_category_list_view, ScrollView product_list_view, TextView is_in_bottom, ProgressBar is_loading) {
            this.set_category_layout = set_category_layout;
            this.product_list_layout = product_list_layout;
            this.set_category_list_view = set_category_list_view;
            this.product_list_view = product_list_view;
            this.is_in_bottom = is_in_bottom;
            this.is_loading = is_loading;
        }

        @Override
        public void run() {
            is_loading_category_data = false;
            which_list = 0;

            ExecutorService executorService = Executors.newSingleThreadExecutor();
            executorService.execute(() -> {
                try {
                    Connection_SQL userSQL = new Connection_SQL();
                    Connection connection = userSQL.connection();
                    String sql = "SELECT * FROM merchant WHERE email = ?;";
                    PreparedStatement preparedStatement = connection.prepareStatement(sql);
                    preparedStatement.setString(1, email);
                    ResultSet set = preparedStatement.executeQuery();
                    while (set.next()) {
                        String category_temp = "";
                        for (int i = 0; i < set.getString("shop_category").length(); i++) {
                            if (set.getString("shop_category").charAt(i) != ',') {
                                category_temp += set.getString("shop_category").charAt(i);
                            } else {
                                if (!category_temp.equals("全部")) {
                                    category.add(category_temp);
                                }
                                category_temp = "";
                            }
                        }
                    }
                    is_loading_category_data = true;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });

            while (!is_loading_category_data) {
                try {
                    Thread.sleep(1);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    set_category_layout.removeAllViews();
                    product_list_layout.removeAllViews();
                    for (int i = 0; i < category.size(); i++) {
                        View view = LayoutInflater.from(Check_Shop_Data_Page.this).inflate(R.layout.category_item_view, null);
                        CardView item = view.findViewById(R.id.item);
                        item_card_view.add(item);
                        TextView item_name = view.findViewById(R.id.item_name);
                        item_name.setText(category.get(i));
                        item_name.setPadding(0, 30, 0, 30);
                        if (i == 0) {
                            Product_Data_Thread productDataThread = new Product_Data_Thread(set_category_layout, product_list_layout, set_category_list_view, product_list_view, category.get(0), item_card_view.get(0));
                            productDataThread.start();
                            loading_which_index = 1;
                            item.setBackgroundColor(Color.rgb(245, 246, 251));
                            last_view = item;
                            product_list_view.smoothScrollTo(0, 0);
                        }
                        int finalI = i;
                        item.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                if (loading_which_index > finalI) {
                                    product_list_view.smoothScrollTo(0, (int) get_view_y.get(finalI).getY());
                                }
                            }
                        });
                        product_list_view.setOnScrollChangeListener(new View.OnScrollChangeListener() {
                            @Override
                            public void onScrollChange(View view, int i, int i1, int i2, int i3) {
                                if (product_list_view.getChildAt(product_list_view.getChildCount() - 1).getBottom() - (product_list_view.getHeight() + product_list_view.getScrollY()) == 0) {
                                    if (loading_which_index < category.size() && loading_which_index == product_data.size()) {
                                        Product_Data_Thread productDataThread = new Product_Data_Thread(set_category_layout, product_list_layout, set_category_list_view, product_list_view, category.get(loading_which_index), item_card_view.get(loading_which_index));
                                        productDataThread.start();
                                        loading_which_index += 1;
                                    } else if (loading_which_index == category.size()) {
                                        is_loading.setVisibility(View.GONE);
                                        is_in_bottom.setText("已经到底啦");
                                        is_in_bottom.setHeight(1500);
                                    }
                                }
                                if (which_list + 1 < viewList.size() && viewList.get(which_list).view.getY() < i1 && viewList.get(which_list + 1).view.getY() <= i1) {
                                    viewList.get(which_list + 1).cardView.setBackgroundColor(Color.rgb(245, 246, 251));
                                    last_view.setBackgroundColor(Color.WHITE);
                                    last_view = viewList.get(which_list + 1).cardView;
                                    which_list += 1;
                                } else if (which_list > 0 && viewList.get(which_list).view.getY() > i1 && viewList.get(which_list - 1).view.getY() <= i1) {
                                    viewList.get(which_list - 1).cardView.setBackgroundColor(Color.rgb(245, 246, 251));
                                    last_view.setBackgroundColor(Color.WHITE);
                                    last_view = viewList.get(which_list - 1).cardView;
                                    which_list -= 1;
                                }
                            }
                        });
                        set_category_layout.addView(view);
                    }
                }
            });
        }
    }

    private class Check_Coupon_Thread extends Thread {
        @Override
        public void run() {
            is_loading_coupon_data = false;
            Coupon_Collect_And_Get_Give couponCollectAndGetGive = new Coupon_Collect_And_Get_Give();
            Coupon_Collect_Points_To_Return_Coupon couponCollectPointsToReturnCoupon = new Coupon_Collect_Points_To_Return_Coupon();
            Coupon_Return_Coupon_For_Placing_An_Order couponReturnCouponForPlacingAnOrder = new Coupon_Return_Coupon_For_Placing_An_Order();
            New_Custom_Receive_A_Discount newCustomReceiveADiscount = new New_Custom_Receive_A_Discount();

            ExecutorService executorService = Executors.newSingleThreadExecutor();
            executorService.execute(() -> {
                try {
                    Connection_SQL userSQL = new Connection_SQL();
                    Connection connection = userSQL.connection();
                    String sql = "SELECT * FROM merchant_coupon_collect_and_get_give WHERE email = ?;";
                    PreparedStatement preparedStatement = connection.prepareStatement(sql);
                    preparedStatement.setString(1, email);
                    ResultSet set = preparedStatement.executeQuery();
                    while (set.next()) {
                        couponCollectAndGetGive.is_set_this_discount = true;
                        couponCollectAndGetGive.how_much_can_use_this = set.getInt("set_how_much_can_use_discount");
                        couponCollectAndGetGive.how_much_in_this_discount = set.getInt("set_how_much_is_the_discount");
                        coupon_data.put("coupon_collect_and_get_give", 1);
                        ;
                    }

                    String sql2 = "SELECT * FROM merchant_coupon_collect_points_to_return_coupon WHERE email = ?;";
                    preparedStatement = connection.prepareStatement(sql2);
                    preparedStatement.setString(1, email);
                    set = preparedStatement.executeQuery();
                    while (set.next()) {
                        couponCollectPointsToReturnCoupon.is_set_this_discount = true;
                        couponCollectPointsToReturnCoupon.how_many_day = set.getInt("set_how_many_day");
                        couponCollectPointsToReturnCoupon.how_many_order = set.getInt("set_how_many_order");
                        couponCollectPointsToReturnCoupon.how_much_is_the_discount = set.getInt("set_how_much_is_the_discount");
                        coupon_data.put("coupon_collect_points_to_return_coupon", 1);
                    }

                    String sql3 = "SELECT * FROM merchant_coupon_return_coupon_for_placing_an_order WHERE email = ?;";
                    preparedStatement = connection.prepareStatement(sql3);
                    preparedStatement.setString(1, email);
                    set = preparedStatement.executeQuery();
                    while (set.next()) {
                        couponReturnCouponForPlacingAnOrder.is_set_this_discount = true;
                        couponReturnCouponForPlacingAnOrder.custom_should_pay_how_many_money = set.getInt("set_custom_should_pay_how_many_money");
                        couponReturnCouponForPlacingAnOrder.how_much_can_use_discount = set.getInt("set_how_much_can_use_discount");
                        couponReturnCouponForPlacingAnOrder.how_much_is_the_discount = set.getInt("set_how_much_is_the_discount");
                        coupon_data.put("coupon_return_coupon_for_placing_an_order", 1);
                    }

                    String sql4 = "SELECT * FROM merchant_new_custom_receive_a_discount WHERE email = ?;";
                    preparedStatement = connection.prepareStatement(sql4);
                    preparedStatement.setString(1, email);
                    set = preparedStatement.executeQuery();
                    while (set.next()) {
                        newCustomReceiveADiscount.is_set_this_discount = true;
                        newCustomReceiveADiscount.reduce_how_many_money = set.getInt("reduce_how_many_money");
                        coupon_data.put("new_custom_receive_a_discount", 1);
                    }
                    is_loading_coupon_data = true;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });

            while (!is_loading_coupon_data) {
                try {
                    Thread.sleep(1);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    int which_coupon_index = 0;
                    for (String res : coupon_data.keySet()) {
                        System.out.println(res);
                        System.out.println(coupon_data.get(res));
                        if (coupon_data.get(res) == 1) {
                            switch (which_coupon_index) {
                                case 0:
                                    View view = LayoutInflater.from(Check_Shop_Data_Page.this).inflate(R.layout.set_coupon_dialog, null);
                                    TextView coupon_name = view.findViewById(R.id.coupon_name);
                                    coupon_name.setText("收藏领" + couponCollectAndGetGive.how_much_in_this_discount + "元券");
                                    set_which_coupon.addView(view);
                                    break;
                                case 1:
                                    View view1 = LayoutInflater.from(Check_Shop_Data_Page.this).inflate(R.layout.set_coupon_dialog, null);
                                    TextView coupon_name1 = view1.findViewById(R.id.coupon_name);
                                    coupon_name1.setText("满" + couponCollectPointsToReturnCoupon.how_many_order + "单返" + couponCollectPointsToReturnCoupon.how_much_is_the_discount + "元券");
                                    set_which_coupon.addView(view1);
                                    break;
                                case 2:
                                    View view2 = LayoutInflater.from(Check_Shop_Data_Page.this).inflate(R.layout.set_coupon_dialog, null);
                                    TextView coupon_name2 = view2.findViewById(R.id.coupon_name);
                                    coupon_name2.setText("实付" + couponReturnCouponForPlacingAnOrder.custom_should_pay_how_many_money + "元返" + couponReturnCouponForPlacingAnOrder.how_much_is_the_discount + "元券");
                                    set_which_coupon.addView(view2);
                                    break;
                                case 3:
                                    View view3 = LayoutInflater.from(Check_Shop_Data_Page.this).inflate(R.layout.set_coupon_dialog, null);
                                    TextView coupon_name3 = view3.findViewById(R.id.coupon_name);
                                    coupon_name3.setText("新客減" + newCustomReceiveADiscount.reduce_how_many_money + "元");
                                    set_which_coupon.addView(view3);
                                    break;
                            }
                        }
                        which_coupon_index += 1;
                    }
                }
            });
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_check_shop_data_page);

        email = getIntent().getStringExtra("email");
        user_email = getIntent().getStringExtra("user_email");
        user_location = getIntent().getStringExtra("user_location");
        shop_name = getIntent().getStringExtra("shop_name");
        delivery_time = getIntent().getIntExtra("delivery_time", 0);
        packing_fee = getIntent().getDoubleExtra("packing_fee", 0);
        reduce_after_delivery_fee = getIntent().getDoubleExtra("delivery_fee", 0);
        reduce_how_many_delivery_fee = getIntent().getDoubleExtra("reduce_how_many_delivery_fee", 0);
        user_name = getIntent().getStringExtra("user_name");
        user_phone_number = getIntent().getStringExtra("user_phone_number");
        user_sex = getIntent().getStringExtra("user_sex");
        how_long = getIntent().getDoubleExtra("how_long", 0);

        View choose_food_page_view_page = LayoutInflater.from(this).inflate(R.layout.choose_food_page, null);

        viewList_in_view_page.add(choose_food_page_view_page);
        viewList_in_view_page.add(LayoutInflater.from(this).inflate(R.layout.choose_discount_food_page, null));
        viewList_in_view_page.add(LayoutInflater.from(this).inflate(R.layout.comment_page, null));
        viewList_in_view_page.add(LayoutInflater.from(this).inflate(R.layout.check_merchant_page, null));

        view_page = findViewById(R.id.view_page);
        choose_food_page_text_view = findViewById(R.id.choose_food_page_text_view);
        choose_discount_food_page_text_view = findViewById(R.id.choose_discount_food_page_text_view);
        comment_page_text_view = findViewById(R.id.comment_page_text_view);
        how_many_comment = findViewById(R.id.how_many_comment);
        check_merchant_page_text_view = findViewById(R.id.check_merchant_page_text_view);
        choose_food_page_view = findViewById(R.id.choose_food_page_view);
        choose_discount_food_page_view = findViewById(R.id.choose_discount_food_page_view);
        comment_page_view = findViewById(R.id.comment_page_view);
        check_merchant_page_view = findViewById(R.id.check_merchant_page_view);
        last_text_view = choose_food_page_text_view;
        last_view_in_view_page = choose_food_page_view;
        set_which_coupon = findViewById(R.id.set_which_coupon);
        how_many_single_order_without_delivery.put(true, 0);
        how_many_single_order_without_delivery.put(false, 0);

        view_page.setAdapter(new ViewPagerAdapter(viewList_in_view_page));

        setChoose_food_page(choose_food_page_view_page);

        checkCouponThread = new Check_Coupon_Thread();
        checkCouponThread.start();

        view_page.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int i) {
                if (i == 0) {
                    choose_food_page_text_view.setTextColor(Color.BLACK);
                    choose_food_page_view.setVisibility(View.VISIBLE);
                    last_text_view.setTextColor(Color.rgb(128, 128, 128));
                    last_view_in_view_page.setVisibility(View.INVISIBLE);
                    last_text_view = choose_food_page_text_view;
                    last_view_in_view_page = choose_food_page_view;
                } else if (i == 1) {
                    choose_discount_food_page_text_view.setTextColor(Color.BLACK);
                    choose_discount_food_page_view.setVisibility(View.VISIBLE);
                    last_text_view.setTextColor(Color.rgb(128, 128, 128));
                    last_view_in_view_page.setVisibility(View.INVISIBLE);
                    last_text_view = choose_discount_food_page_text_view;
                    last_view_in_view_page = choose_discount_food_page_view;
                } else if (i == 2) {
                    comment_page_text_view.setTextColor(Color.BLACK);
                    comment_page_view.setVisibility(View.VISIBLE);
                    last_text_view.setTextColor(Color.rgb(128, 128, 128));
                    last_view_in_view_page.setVisibility(View.INVISIBLE);
                    last_text_view = comment_page_text_view;
                    last_view_in_view_page = comment_page_view;
                } else if (i == 3) {
                    check_merchant_page_text_view.setTextColor(Color.BLACK);
                    check_merchant_page_view.setVisibility(View.VISIBLE);
                    last_text_view.setTextColor(Color.rgb(128, 128, 128));
                    last_view_in_view_page.setVisibility(View.INVISIBLE);
                    last_text_view = check_merchant_page_text_view;
                    last_view_in_view_page = check_merchant_page_view;
                }
            }

            @Override
            public void onPageScrollStateChanged(int i) {
            }
        });
    }

    public void set_dialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        LayoutInflater inflater1 = LayoutInflater.from(this);
        builder.setView(inflater1.inflate(R.layout.loading, null));
        builder.setCancelable(false);

        dialog = builder.create();
        dialog.show();
    }

    public void setChoose_food_page(View view) {
        LinearLayout set_category_layout = view.findViewById(R.id.set_category_layout);
        LinearLayout product_list_layout = view.findViewById(R.id.product_list_layout);
        ScrollView product_list_view = view.findViewById(R.id.product_list_view);
        ScrollView set_category_list_view = view.findViewById(R.id.set_category_list_view);
        TextView is_in_bottom = view.findViewById(R.id.is_in_bottom);
        ProgressBar is_loading = view.findViewById(R.id.is_loading);
        set_check_out_dialog = view.findViewById(R.id.set_check_out_dialog);
        go_to_check_page = view.findViewById(R.id.go_to_check_page);
        should_pay_how_much = view.findViewById(R.id.should_pay_how_much);
        reduce_how_many_money = view.findViewById(R.id.reduce_how_many_money);
        delivery_fee = view.findViewById(R.id.delivery_fee);
        how_many_product = view.findViewById(R.id.how_many_product);
        set_category_layout.addView(LayoutInflater.from(view.getContext()).inflate(R.layout.load_data, null));
        product_list_layout.addView(LayoutInflater.from(view.getContext()).inflate(R.layout.load_data, null));
        Category_Data_Thread categoryDataThread = new Category_Data_Thread(set_category_layout, product_list_layout, set_category_list_view, product_list_view, is_in_bottom, is_loading);
        categoryDataThread.start();

        go_to_check_page.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                check_page();
            }
        });
    }

    public void setChoose_discount_food_page() {

    }

    public void setComment_page() {

    }

    public void setCheck_merchant_page() {

    }

    private float dipToPx(int dipValue) {
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                dipValue,
                this.getResources().getDisplayMetrics());
    }

    private float getScreenWidth() {
        return this.getResources().getDisplayMetrics().widthPixels;
    }

    public void check_page() {
        Dialog dialog = new Dialog(this);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.check_out_page);

        TextView location_name = dialog.findViewById(R.id.location_name);
        location_name.setText(user_location);

        user_name_text_view = dialog.findViewById(R.id.user_name);
        user_sex_text_view = dialog.findViewById(R.id.user_sex);
        user_phone_number_text_view = dialog.findViewById(R.id.user_phone_number);
        user_name_text_view.setText(user_name);
        user_sex_text_view.setText(user_sex);
        user_phone_number_text_view.setText(user_phone_number);

        Calendar nowTime = Calendar.getInstance();
        nowTime.add(Calendar.MINUTE, delivery_time);

        Calendar nowTime2 = Calendar.getInstance();
        nowTime2.add(Calendar.MINUTE, delivery_time + 20);

        TextView expected_time = dialog.findViewById(R.id.expected_time);
        expected_time.setText("预计" + nowTime.getTime().getHours() + ":" + nowTime.getTime().getMinutes() + "-" + nowTime2.getTime().getHours() + ":" + nowTime2.getTime().getMinutes());

        TextView shop_name = dialog.findViewById(R.id.shop_name);
        shop_name.setText(this.shop_name);

        TextView how_many_packing_fee = dialog.findViewById(R.id.how_many_packing_fee);
        how_many_packing_fee.setText(String.format("%.2f", buy_how_many_product * packing_fee));

        TextView shop_is_activity_to_reduce_user_delivery_fee = dialog.findViewById(R.id.shop_is_activity_to_reduce_user_delivery_fee);
        if (this.reduce_how_many_delivery_fee == 0) {
            shop_is_activity_to_reduce_user_delivery_fee.setVisibility(View.GONE);
        } else {
            shop_is_activity_to_reduce_user_delivery_fee.setText("活动减" + String.format("%.2f", this.reduce_how_many_delivery_fee) + "元配送费");
        }

        TextView original_delivery_fee_text_view = dialog.findViewById(R.id.original_delivery_fee);
        if (this.reduce_how_many_delivery_fee == 0) {
            original_delivery_fee_text_view.setVisibility(View.GONE);
        } else {
            original_delivery_fee_text_view.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
            original_delivery_fee_text_view.setText("¥" + String.format("%.2f", this.reduce_after_delivery_fee));
        }

        TextView reduce_after_delivery_fee_text_view = dialog.findViewById(R.id.reduce_after_delivery_fee);
        if (this.reduce_after_delivery_fee - this.reduce_how_many_delivery_fee > 0) {
            reduce_after_delivery_fee_text_view.setTextColor(Color.BLACK);
            reduce_after_delivery_fee_text_view.setText("¥" + String.format("%.2f", this.reduce_after_delivery_fee - this.reduce_how_many_delivery_fee));
        } else {
            reduce_after_delivery_fee_text_view.setTextColor(Color.RED);
            reduce_after_delivery_fee_text_view.setText("免配送费");
        }

        TextView discount_how_many_dollars = dialog.findViewById(R.id.discount_how_many_dollars);
        discount_how_many_dollars.setText("已优惠¥" + String.format("%.2f", this.reduce_how_many_dollars));

        TextView user_should_pay_how_many_dollars = dialog.findViewById(R.id.user_should_pay_how_many_dollars);
        if (reduce_after_delivery_fee_text_view.getText().toString().equals("免配送费")) {
            user_should_pay_how_many_dollars.setText("" + String.format("%.2f", (this.how_many_dollars + (buy_how_many_product * packing_fee))));
        }
        else {
            user_should_pay_how_many_dollars.setText("" + String.format("%.2f", (this.how_many_dollars + (buy_how_many_product * packing_fee) + (this.reduce_after_delivery_fee - this.reduce_how_many_delivery_fee))));
        }

        TextView should_pay_how_much = dialog.findViewById(R.id.should_pay_how_much);
        if (reduce_after_delivery_fee_text_view.getText().toString().equals("免配送费")) {
            should_pay_how_much.setText("" + String.format("%.2f", (this.how_many_dollars + (buy_how_many_product * packing_fee))));
        }
        else {
            should_pay_how_much.setText("" + String.format("%.2f", (this.how_many_dollars + (buy_how_many_product * packing_fee) + (this.reduce_after_delivery_fee - this.reduce_how_many_delivery_fee))));
        }

        TextView reduce_how_many_money = dialog.findViewById(R.id.reduce_how_many_money);
        reduce_how_many_money.setText("" + String.format("%.2f", this.reduce_how_many_dollars));

        note_text = dialog.findViewById(R.id.note_text);
        choose_how_many_table_ware = dialog.findViewById(R.id.choose_how_many_table_ware);

        LinearLayout buy_which_product = dialog.findViewById(R.id.buy_which_product);

        for (String key : product_second_data.keySet()) {
            if (product_second_data.get(key).getHow_many() != 0) {
                View view = LayoutInflater.from(this).inflate(R.layout.check_out_page_product_view, null);

                if (product_second_data.get(key).getThis_product_has_how_many_discount_product() > 0) {
                    show_check_out_product_view(buy_which_product, view, product_second_data.get(key).getMain_name(), product_second_data.get(key).getSpecification_or_attributes(), product_second_data.get(key).getProduct_pic(), product_second_data.get(key).getThis_product_has_how_many_discount_product(), product_second_data.get(key).getThis_product_has_how_many_discount_product() * product_second_data.get(key).getOne_this_product_original_price(), product_second_data.get(key).getThis_product_has_how_many_discount_product() * product_second_data.get(key).getOne_this_product_discount());
                    if (product_second_data.get(key).getHow_many() - product_second_data.get(key).getThis_product_has_how_many_discount_product() > 0) {
                        View view2 = LayoutInflater.from(this).inflate(R.layout.check_out_page_product_view, null);
                        show_check_out_product_view(buy_which_product, view2, product_second_data.get(key).getMain_name(), product_second_data.get(key).getSpecification_or_attributes(), product_second_data.get(key).getProduct_pic(), product_second_data.get(key).getHow_many() - product_second_data.get(key).getThis_product_has_how_many_discount_product(), 0, (product_second_data.get(key).getHow_many() - product_second_data.get(key).getThis_product_has_how_many_discount_product()) * product_second_data.get(key).getOne_this_product_original_price());
                    }
                }
                else {
                    show_check_out_product_view(buy_which_product, view, product_second_data.get(key).getMain_name(), product_second_data.get(key).getSpecification_or_attributes(), product_second_data.get(key).getProduct_pic(), product_second_data.get(key).getHow_many() - product_second_data.get(key).getThis_product_has_how_many_discount_product(), 0, product_second_data.get(key).getHow_many() * product_second_data.get(key).getOne_this_product_original_price());
                }
            }
        }

        RelativeLayout set_note = dialog.findViewById(R.id.note);
        set_note.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Check_Shop_Data_Page.this, Set_Note_Page.class);
                startActivityForResult(intent, 1);
            }
        });

        RelativeLayout choose_table_ware = dialog.findViewById(R.id.choose_table_ware);
        choose_table_ware.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (user_name.isEmpty() || user_sex.isEmpty() || user_phone_number.isEmpty()) {
                    set_user_data();
                }
                else {
                    set_table_ware();
                }
            }
        });

        RelativeLayout submit_order_layout = dialog.findViewById(R.id.submit_order_layout);
        submit_order_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (user_name.isEmpty() || user_sex.isEmpty() || user_phone_number.isEmpty()) {
                    set_user_data();
                }
                else if (choose_how_many_table_ware.getText().toString().equals("请选择")) {
                    set_table_ware();
                }
                else {
                    set_dialog();
                    String product_data = "";
                    how_many_product_category = 0;
                    all_has_how_many_product = 0;
                    for (String key : product_second_data.keySet()) {
                        if (product_second_data.get(key).getHow_many() != 0) {
                            how_many_product_category += 1;
                            all_has_how_many_product += product_second_data.get(key).getHow_many();
                            product_data += product_second_data.get(key).getMain_name();
                            product_data += "#";
                            product_data += product_second_data.get(key).getSpecification_or_attributes();
                            product_data += "#";
                            product_data += String.valueOf(product_second_data.get(key).getOne_this_product_discount());
                            product_data += "#";
                            product_data += String.valueOf(product_second_data.get(key).getOne_this_product_original_price());
                            product_data += "#";
                            product_data += String.valueOf(product_second_data.get(key).getHow_many());
                            product_data += "#";
                            product_data += String.valueOf(product_second_data.get(key).getThis_product_has_how_many_discount_product());
                            product_data += "#";
                            product_data += "该商品的数据已全部添加";
                        }
                    }
                    dialog.dismiss();
                    Check_Shop_Data_Page.this.dialog.dismiss();
                    Intent intent = new Intent(Check_Shop_Data_Page.this, Choose_Pay_Method_Page.class);
                    intent.putExtra("price", should_pay_how_much.getText().toString());
                    intent.putExtra("shop_name", shop_name.getText().toString());
                    intent.putExtra("order_address", user_location);
                    intent.putExtra("shop_email", email);
                    intent.putExtra("user_email", user_email);
                    intent.putExtra("user_name", user_name);
                    intent.putExtra("user_sex", user_sex);
                    intent.putExtra("user_phone_number", user_phone_number);
                    intent.putExtra("how_many_km", how_long);
                    intent.putExtra("note", note_text.getText().toString());
                    intent.putExtra("table_ware", choose_how_many_table_ware.getText().toString());
                    intent.putExtra("how_many_product", how_many_product_category);
                    intent.putExtra("all_product_num", all_has_how_many_product);
                    intent.putExtra("product_data", product_data);
                    intent.putExtra("packing_fee", how_many_packing_fee.getText().toString());
                    if (reduce_after_delivery_fee_text_view.getText().toString().equals("免配送费")) {
                        intent.putExtra("delivery_fee", reduce_after_delivery_fee_text_view.getText().toString());
                    }
                    else {
                        intent.putExtra("delivery_fee", reduce_after_delivery_fee_text_view.getText().toString().substring(1));
                    }
                    intent.putExtra("this_order_has_how_many_discount", reduce_how_many_money.getText().toString());
                    startActivity(intent);
                    finish();
                }
            }
        });

        dialog.show();
        dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, (int) (getResources().getDisplayMetrics().heightPixels * 0.9));
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
        dialog.getWindow().setGravity(Gravity.BOTTOM);
    }

    public void show_check_out_product_view(LinearLayout buy_which_product, @NonNull View view, String main_name, String specification_or_attributes, byte[] product_pic, int choose_how_many_product, double original_price, double after_product_price) {
        TextView product_name = view.findViewById(R.id.product_name);
        product_name.setText(main_name);

        TextView product_specification_or_attributes = view.findViewById(R.id.product_specification_or_attributes);
        if (specification_or_attributes.isEmpty()) {
            product_specification_or_attributes.setVisibility(View.GONE);
        }
        else {
            product_specification_or_attributes.setText(specification_or_attributes);
        }

        ImageView product_image = view.findViewById(R.id.product_image);
        Bitmap decodedImage = BitmapFactory.decodeByteArray(product_pic, 0, product_pic.length);
        product_image.setImageBitmap(decodedImage);

        TextView choose_how_many_this_product = view.findViewById(R.id.choose_how_many_this_product);
        choose_how_many_this_product.setText("x" + choose_how_many_product);

        TextView this_product_original_price = view.findViewById(R.id.this_product_original_price);
        TextView reduce_after_product_price = view.findViewById(R.id.reduce_after_product_price);
        if (original_price == 0) {
            this_product_original_price.setVisibility(View.GONE);
            reduce_after_product_price.setText("¥" + after_product_price);
        } else {
            this_product_original_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
            this_product_original_price.setText("¥" + original_price);
            reduce_after_product_price.setText("¥" + after_product_price);
        }

        buy_which_product.addView(view);
    }

    public void set_user_data() {
        Dialog dialog = new Dialog(this);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.set_location_name_dialog);

        EditText set_name = dialog.findViewById(R.id.set_name);
        RadioGroup choose_sex = dialog.findViewById(R.id.choose_sex);
        choose_sex.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton type = findViewById(radioGroup.getCheckedRadioButtonId());
                user_sex_temp = type.getText().toString();
            }
        });
        EditText set_phone_number = dialog.findViewById(R.id.set_phone_number);
        Button save = dialog.findViewById(R.id.save);
        save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (set_name.getText().toString().isEmpty() || set_phone_number.getText().toString().isEmpty()) {
                    Toast.makeText(Check_Shop_Data_Page.this, "", Toast.LENGTH_SHORT).show();
                }
                else {
                    user_sex = user_sex_temp;
                    user_name = set_name.getText().toString();
                    user_phone_number = set_phone_number.getText().toString();
                    user_phone_number_text_view.setText(user_phone_number);
                    user_name_text_view.setText(user_name);
                    user_sex_text_view.setText(user_sex);
                    dialog.dismiss();
                }
            }
        });

        dialog.show();
        dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        dialog.getWindow().getAttributes().windowAnimations = R.style.Show_Specification_Animation;
        dialog.getWindow().setGravity(Gravity.BOTTOM);
    }

    public void set_table_ware() {
        Dialog dialog = new Dialog(this);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.set_choose_table_ware_dialog);

        TextView location = dialog.findViewById(R.id.location);
        location.setText(user_location);

        LinearLayout choose_has_table_ware = dialog.findViewById(R.id.choose_has_table_ware);
        LinearLayout choose_no_table_ware = dialog.findViewById(R.id.choose_no_table_ware);
        LinearLayout should_choose_has_table_ware = dialog.findViewById(R.id.should_choose_has_table_ware);
        TextView choose_has_table_ware_text_view = dialog.findViewById(R.id.choose_has_table_ware_text_view);
        TextView choose_no_table_ware_text_view_1 = dialog.findViewById(R.id.choose_no_table_ware_text_view_1);
        TextView choose_no_table_ware_text_view_2 = dialog.findViewById(R.id.choose_no_table_ware_text_view_2);
        LinearLayout choose_merchant_take_how_many = dialog.findViewById(R.id.choose_merchant_take_how_many);
        LinearLayout choose_how_many_table_ware = dialog.findViewById(R.id.choose_how_many_table_ware);
        TextView choose_merchant_take_how_many_text_view = dialog.findViewById(R.id.choose_merchant_take_how_many_text_view);
        TextView reduce_table_ware = dialog.findViewById(R.id.reduce_table_ware);
        TextView how_many_table_ware = dialog.findViewById(R.id.how_many_table_ware);
        TextView plus_table_ware = dialog.findViewById(R.id.plus_table_ware);
        Button save = dialog.findViewById(R.id.save);
        last_choose_which_table_ware = choose_has_table_ware;
        last_choose_how_many_table_ware = choose_merchant_take_how_many;

        choose_has_table_ware.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (last_choose_which_table_ware != choose_has_table_ware) {
                    choose_has_table_ware.setBackgroundResource(R.drawable.border_white_2_10dp);
                    should_choose_has_table_ware.setVisibility(View.VISIBLE);
                    choose_no_table_ware.setBackgroundResource(R.drawable.border_bar_color_10dp);
                    choose_has_table_ware_text_view.setTextColor(Color.rgb(224, 143, 87));
                    choose_no_table_ware_text_view_1.setTextColor(Color.BLACK);
                    choose_no_table_ware_text_view_2.setTextColor(Color.rgb(128, 128, 128));
                    last_choose_which_table_ware = choose_has_table_ware;
                }
            }
        });

        choose_no_table_ware.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (last_choose_which_table_ware != choose_no_table_ware) {
                    choose_no_table_ware.setBackgroundResource(R.drawable.border_white_2_10dp);
                    should_choose_has_table_ware.setVisibility(View.GONE);
                    choose_has_table_ware.setBackgroundResource(R.drawable.border_bar_color_10dp);
                    choose_has_table_ware_text_view.setTextColor(Color.BLACK);
                    choose_no_table_ware_text_view_1.setTextColor(Color.rgb(224, 143, 87));
                    choose_no_table_ware_text_view_2.setTextColor(Color.rgb(224, 143, 87));
                    last_choose_which_table_ware = choose_no_table_ware;
                }
            }
        });

        choose_merchant_take_how_many.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (last_choose_how_many_table_ware != choose_merchant_take_how_many) {
                    choose_merchant_take_how_many.setBackgroundResource(R.drawable.border_white_2_10dp);
                    choose_merchant_take_how_many_text_view.setTextColor(Color.rgb(224, 143, 87));
                    choose_how_many_table_ware.setBackgroundResource(R.drawable.border_bar_color_10dp);
                    last_choose_how_many_table_ware = choose_merchant_take_how_many;
                }
            }
        });

        choose_how_many_table_ware.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (last_choose_how_many_table_ware != choose_how_many_table_ware) {
                    choose_how_many_table_ware.setBackgroundResource(R.drawable.border_white_2_10dp);
                    choose_merchant_take_how_many_text_view.setTextColor(Color.BLACK);
                    choose_merchant_take_how_many.setBackgroundResource(R.drawable.border_bar_color_10dp);
                    last_choose_how_many_table_ware = choose_how_many_table_ware;
                    reduce_table_ware.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (table_ware_num == 1) {
                                Toast.makeText(Check_Shop_Data_Page.this, "最少选择1份", Toast.LENGTH_SHORT).show();
                            }
                            else {
                                table_ware_num -= 1;
                                how_many_table_ware.setText(table_ware_num + "份");
                            }
                        }
                    });

                    plus_table_ware.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (table_ware_num == 15) {
                                Toast.makeText(Check_Shop_Data_Page.this, "最多选择15份", Toast.LENGTH_SHORT).show();
                            }
                            else {
                                table_ware_num += 1;
                                how_many_table_ware.setText(table_ware_num + "份");
                            }
                        }
                    });
                }
            }
        });

        save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (last_choose_which_table_ware == choose_no_table_ware) {
                    Check_Shop_Data_Page.this.choose_how_many_table_ware.setText("已选无需餐具");
                }
                else {
                    if (last_choose_how_many_table_ware == choose_merchant_take_how_many) {
                        Check_Shop_Data_Page.this.choose_how_many_table_ware.setText("按餐量提供");
                    }
                    else {
                        Check_Shop_Data_Page.this.choose_how_many_table_ware.setText(table_ware_num + "份");
                    }
                }
                dialog.dismiss();
            }
        });

        dialog.show();
        dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        dialog.getWindow().getAttributes().windowAnimations = R.style.Show_Specification_Animation;
        dialog.getWindow().setGravity(Gravity.BOTTOM);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        switch (requestCode) {
            case 1: {
                if (data != null) {
                    if (data.getStringExtra("note").isEmpty()) {
                        note_text.setText("请填写您的要求");
                    }
                    else {
                        note_text.setText(data.getStringExtra("note"));
                    }
                }
                break;
            }
        }
    }
}